Hi <#C01AHCD885S|ask-ai>, Using Airbyte cloud curr...
# ask-ai
m
Hi #ask-ai, Using Airbyte cloud currently, and building a new connector through the UI for an API source. via oAUTH2. The source API needs client_id, client_secret so no problem for that, but it needs a third parameter (id) in order to generate the token. In the UI, I don't see where I can add a custom extra parameter. I tought this might not be the first time this issue has been raised, so I tought to ask the community. Ideally, we would like to avoid going through a development (cdk) because the client will not be able to maintain the code in the long run. Thanks for any guidance or help on this.
k
Yes, this is a common scenario when working with OAuth2 APIs that require additional parameters beyond the standard
client_id
and
client_secret
. Airbyte’s Declarative OAuth Connector Specification is designed to be flexible and allows you to inject custom parameters into the OAuth flow without writing code. How to add a custom parameter (like
id
) in Airbyte Cloud UI:
When configuring OAuth2 in the Connector Builder UI, you can use the "Declarative OAuth Connector Specification" to define custom parameters for the token exchange step. Specifically, you can add extra fields to the access token request, such as custom query parameters or headers. - In the OAuth2 configuration section, look for options like Access Token Headers and Access Token Query Params (Json Encoded). These allow you to specify additional parameters that should be included when exchanging the authorization code for an access token. - For example, you can add your custom
id
parameter as a query parameter or in the request body, depending on what the API expects. Here’s what the documentation says: > The best way to implement OAuth is to enable Declarative OAuth Connector Specification. ... You can also configure these optional fields if they're required by the source. > > - Access Token Headers: ... optional headers to inject while exchanging the auth_code to access_token ... > - Access Token Query Params (Json Encoded): ... optional query parameters to inject while exchanging the auth_code to access_token ... > - ... [other overrides for custom parameter names] ... > > [See more details in the official docs.](https://docs.airbyte.com/platform/next/connector-development/connector-builder-ui/authentication#oauth-2) Summary: You do not need to use the CDK for this use case. In the Connector Builder UI, use the Declarative OAuth options to add your custom parameter (
id
) to the token request. This approach is maintainable and does not require code changes. If you need to inject the parameter in a very custom way (e.g., in a non-standard location), Airbyte’s declarative OAuth also supports custom parameter injection via configuration, making it suitable for most use cases without code changes. If you have trouble finding the exact field in the UI, refer to the "Access Token Query Params" or "Access Token Headers" options in the OAuth2 configuration section of the Connector Builder UI. Let me know if you need step-by-step guidance for your specific API!
m
@kapa.ai can you elaborate how to add the extra parameter, especially as an input. I tried this on the Access Token Headers part, {"Authorization":"Basic {{ {{ client_id_value }}:{{ client_secret_value }}:{{ id_value}} | base64Encoder }}"}
k
A message from kapa.ai
To add an extra parameter (such as
id
) as an input in the Airbyte Connector Builder UI for OAuth2, you should follow these steps: 1. Add the extra parameter as a user input: - Go to the Inputs section of your connector in the Builder UI. - Click Add new user input. - Set the Input name to something like "ID". - Set the Field ID to
id
. - Set the Type to "String". - Mark it as Required if needed. - Click Create. This will make
id
available as
{{ config['id'] }}
in your connector configuration. 2. Inject the extra parameter into the OAuth flow: - In the OAuth2 configuration, when specifying the Access Token Params (or similar field for the token request body), add your custom parameter using the template variable. For example:
Copy code
yaml    access_token_params:      client_id: "{{ client_id_value }}"      client_secret: "{{ client_secret_value }}"      id: "{{ config['id'] }}"      redirect_uri: "{{ redirect_uri_value }}"      code: "{{ auth_code_value }}"
This will ensure that the
id
parameter, as provided by the user, is included in the body of the access token request. Note: - The Access Token Headers section is for HTTP headers, not for request body or query parameters. If your API requires the
id
in the body or as a query parameter, use Access Token Params instead. - The template variable for your custom input will be
{{ config['id'] }}
. Reference: This approach is supported by Airbyte’s declarative OAuth, which allows you to add custom parameters to the token request by defining them in the configuration, and user inputs can be referenced using the
{{ config['your_field_id'] }}
syntax. See the [official documentation for advanced OAuth configuration](https://docs.airbyte.com/platform/connector-development/config-based/advanced-topics/oauth#advanced-case-access-token-url-query-parameters-should-be-json-encoded) for an example of adding custom parameters to the access token request. If you need to encode values (e.g., base64), Airbyte supports template variables, but the documentation does not specify support for inline encoding functions like
base64Encoder
in the declarative YAML. If you need to encode a value, you may need to pre-encode it or check if the UI supports such a function. Summary: - Add your extra parameter as a user input. - Reference it in the OAuth configuration using
{{ config['id'] }}
in the appropriate section (usually
access_token_params
). - Do not use the Headers section unless the API expects the value in an HTTP header. If you need more specific guidance for your API’s requirements, please provide details on where the
id
parameter needs to be sent (body, query, or header).
m
@kapa.ai I used the "Access Token Query Params (Json Encoded)" to put the following { "{{ client_id }}":"{{ client_id_value }}", "{{ client_secret }}":"{{ client_secret_value }}", "{{ site_id }}":"{{ config['site_id'] }}" } I received the following error. airbyte_cdk.sources.concurrent_source.stream_thread_exception.StreamThreadException: Exception while syncing stream Connection: 401 Client Error: Unauthorized for url:
k
A message from kapa.ai
Based on the official Airbyte documentation, when using the Access Token Query Params (Json Encoded) field in the Connector Builder UI for OAuth2, you should provide the parameter names as plain strings, not as Jinja template variables. The values can use Jinja expressions to reference your configuration or input fields. Correct format:
Copy code
json {   "client_id": "{{ client_id_value }}",   "client_secret": "{{ client_secret_value }}",   "site_id": "{{ config['site_id'] }}" }
- The keys (
client_id
,
client_secret
,
site_id
) should be plain strings matching what the API expects. - The values can use Jinja templating to inject the actual values from your configuration. Why your approach failed: You used
{{ client_id }}
and similar expressions as keys, which would result in the actual key names being
{{ client_id }}
instead of
client_id
. Most APIs expect the key to be exactly
client_id
, not a template string. Reference: > Use the
access_token_params
property to include the JSON-encoded params in the body of the request. > Example rendered
access_token_params
>
Copy code
> {   >   "client_id": "YOUR_CLIENT_ID_123",   >   "client_secret": "YOUR_CLIENT_SECRET_123",   >   "redirect_uri": "https://cloud.airbyte.com"   > } >
[See documentation for details.](https://docs.airbyte.com/platform/connector-development/config-based/advanced-topics/oauth#advanced-case-access-token-url-query-parameters-should-be-json-encoded) Action: Update your configuration to use plain string keys as shown above. This should resolve the 401 error if the credentials and parameters are otherwise correct. If you continue to receive a 401 error, double-check that: - The values for
client_id
,
client_secret
, and
site_id
are correct. - The API expects these parameters in the body as JSON (not as query parameters or headers). If the API expects these as query parameters, you may need to use a different configuration field. The documentation above is for JSON-encoded body parameters, which is the most common pattern for OAuth2 token requests.