Skip to content

Fix FreshDesk Auth #217

@nickmazurenko

Description

@nickmazurenko

Freshdesk: set_options_post_auth not firing — subdomain validation and base64 token construction broken

Problem

The Freshdesk connection relies on set_options_post_auth to:

  1. Validate and sanitize the subdomain option
  2. Construct the base64 authentication token (btoa(apiKey + ':X'))
  3. Build the full API URL

However, set_options_post_auth is not firing. As a result:

  • The token connection option is never populated
  • The subdomain is never validated
  • API calls fail because there is no usable auth token

Why This Matters

Without the function firing:

  • No auth token — the token field in conn_opts remains empty, so all API requests that use Authorization: Bearer ${token} fail
  • No subdomain validation — users can enter invalid values (e.g., full URLs like mycompany.freshdesk.com instead of just mycompany), leading to malformed URLs like https://mycompany.freshdesk.com.freshdesk.com
  • Connection ping succeeds or fails silently — the health check at GET /api/v2/agents/me may not use the token at all if the header isn't set up correctly

Current Implementation

In src/apps/freshdesk/index.ts:

rest: {
  url: 'https://{{subdomain}}.freshdesk.com',
  oauth2_grant_type: 'none',
  ping_path: '/api/v2/agents/me',
},
rest_modifiers: {
  options: FRESHDESK_CONN_OPTIONS,
  required_options: 'subdomain,apiKey',
  url_template_options: ['subdomain'],
  set_options_post_auth: (context) => {
    // This function is NOT being called
    const subdomain = context.conn_opts?.subdomain;
    const apiKey = context.conn_opts?.apiKey;
    if (!subdomain || !apiKey) {
      throw new Error('Subdomain and API Key are required');
    }
    return {
      url: `https://${subdomain}.freshdesk.com`,
      apiKey,
      subdomain,
      token: btoa(`${apiKey}:X`),
    };
  },
},

Requirements

A function is needed that runs:

  • On connection creation
  • After connection options are changed

This function must:

  1. Sanitize the subdomain

    • Trim whitespace
    • Strip https://, http://, and .freshdesk.com if the user accidentally includes them
    • Validate the value contains only valid subdomain characters (alphanumeric + hyphens)
    • Return a clear error if the subdomain is invalid
  2. Build the base64 auth token

    • Encode apiKey:X as base64 (Freshdesk convention — X is a dummy password)
    • Store as token in connection options
  3. Verify the connection works

    • Optionally make a test request to confirm the subdomain and API key are valid

Possible Solutions

  1. Investigate why set_options_post_auth isn't firing — It may be related to the oauth2_grant_type: 'none' configuration, or an interaction with url_template_options. Other non-OAuth apps like Active Campaign and Mautic also use set_options_post_auth with oauth2_grant_type: 'none', but they also use url_from_option which may trigger the function differently.

  2. Add set_options_post_auth_code — This variant is used by Trello, Slack, and ZohoCRM to run the same logic both after OAuth auth and after option changes. Assigning the same function to both set_options_post_auth and set_options_post_auth_code ensures it runs in all scenarios.

  3. Use connection_update_option — This modifier (used by DocuSign) fires when a specific option value changes. It could be used to re-validate and reconstruct the URL/token when subdomain or apiKey changes.

Additional Note

Verify that the auth header type is correct. Freshdesk API documentation specifies Basic authentication (Authorization: Basic <base64>). The current implementation sends the token as a Bearer token. If the Qore platform handles the Basic auth header construction automatically from the token option, this may be fine — otherwise it needs to be corrected.

Relevant Files

Reference Patterns

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingenhancementNew feature or request

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions