<@U04S8PLJWMT> I would like to create OAuth connec...
# ask-ai
a
@kapa.ai I would like to create OAuth connector with
Authorize
and
Token
endpoints using
grant_type=authorization_code
. Could you please help with sample configuration?
k
Certainly! Below is a sample configuration for an Airbyte OAuth connector using the
authorization_code
grant type, with
Authorize
(consent) and
Token
endpoints. This example follows the Declarative OAuth 2.0 specification and assumes a standard OAuth flow with no custom parameters or headers. ### Example Declarative OAuth Configuration
Copy code
yaml advanced_auth:   auth_flow_type: oauth2.0   oauth_config_specification:     oauth_connector_input_specification:       consent_url: >-         https://yourconnectorservice.com/oauth/authorize?client_id={{client_id}}&redirect_uri={{redirect_uri}}&response_type=code&scope={{scope}}&state={{state}}       access_token_url: >-         https://yourconnectorservice.com/oauth/token?client_id={{client_id}}&client_secret={{client_secret}}&code={{auth_code}}&grant_type=authorization_code&redirect_uri={{redirect_uri}}     complete_oauth_output_specification:       required:         - access_token       properties:         access_token:           type: string           path_in_connector_config:             - access_token           path_in_oauth_response:             - access_token     complete_oauth_server_input_specification:       required:         - client_id         - client_secret       properties:         client_id:           type: string         client_secret:           type: string     complete_oauth_server_output_specification:       required:         - client_id         - client_secret       properties:         client_id:           type: string           path_in_connector_config:             - client_id         client_secret:           type: string           path_in_connector_config:             - client_secret
#### Example OAuth Endpoints - Authorize (Consent) URL:
https://yourconnectorservice.com/oauth/authorize?client_id=YOUR_CLIENT_ID&redirect_uri=YOUR_REDIRECT_URI&response_type=code&scope=YOUR_SCOPE&state=SOME_STATE
- Token URL:
https://yourconnectorservice.com/oauth/token?client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET&code=AUTH_CODE&grant_type=authorization_code&redirect_uri=YOUR_REDIRECT_URI
#### Example Token Response
Copy code
json {   "access_token": "YOUR_ACCESS_TOKEN_123" }
This configuration covers the basic OAuth 2.0 flow with the
authorization_code
grant type. You can extend it to include
refresh_token
and other fields as needed, depending on your API's requirements. For more details and advanced use cases, see the [Airbyte documentation on Declarative OAuth 2.0](https://docs.airbyte.com/platform/next/connector-development/config-based/advanced-topics/oauth#basic-oauth-flow) and [common use-cases](https://docs.airbyte.com/platform/next/connector-development/config-based/advanced-topics/oauth#common-use-cases-and-examples) for additional examples and options.<br> Sources: [Basic OAuth Flow](https://docs.airbyte.com/platform/next/connector-development/config-based/advanced-topics/oauth#basic-oauth-flow), [Common Use-Cases and Examples](https://docs.airbyte.com/platform/next/connector-development/config-based/advanced-topics/oauth#common-use-cases-and-examples)
a
@kapa.ai thank you, the
Token
endpoint accept
POST
method with HTTP Basic Auth. Could you please review the config?
k
A message from kapa.ai
Certainly! If your
Token
endpoint requires a
POST
request and uses HTTP Basic Auth (where the client ID and client secret are sent as a base64-encoded header), you should: - Use the
access_token_url
without query parameters for client credentials. - Add an
access_token_headers
section to include the
Authorization
header with the value as a base64-encoded string of
client_id:client_secret
. Here’s how you can configure this in your Airbyte declarative OAuth spec:
Copy code
yaml advanced_auth:   auth_flow_type: oauth2.0   oauth_config_specification:     oauth_connector_input_specification:       consent_url: >-         https://yourconnectorservice.com/oauth/authorize?client_id={{client_id}}&redirect_uri={{redirect_uri}}&response_type=code&scope={{scope}}&state={{state}}       access_token_url: >-         https://yourconnectorservice.com/oauth/token       access_token_headers:         Authorization: "Basic {{ (client_id ~ ':' ~ client_secret) | b64encode }}"       access_token_params:         grant_type: "authorization_code"         code: "{{auth_code}}"         redirect_uri: "{{redirect_uri}}"     complete_oauth_output_specification:       required:         - access_token       properties:         access_token:           type: string           path_in_connector_config:             - access_token           path_in_oauth_response:             - access_token     complete_oauth_server_input_specification:       required:         - client_id         - client_secret       properties:         client_id:           type: string         client_secret:           type: string     complete_oauth_server_output_specification:       required:         - client_id         - client_secret       properties:         client_id:           type: string           path_in_connector_config:             - client_id         client_secret:           type: string           path_in_connector_config:             - client_secret
Key points: - The
access_token_url
is just the endpoint, no credentials in the URL. - The
Authorization
header is set using the base64-encoded
client_id:client_secret
string. - The
access_token_params
are sent in the POST body, including
grant_type
,
code
, and
redirect_uri
. This approach matches the advanced example in the Airbyte documentation for using HTTP Basic Auth in the token request header, including the use of the Jinja filter for base64 encoding: [Advanced Case: client secret is a request header not a query parameter](https://docs.airbyte.com/platform/next/connector-development/config-based/advanced-topics/oauth#advanced-case-client-secret-is-a-request-header-not-a-query-parameter). If your API requires the
Authorization
header to be named differently, you can adjust the header key accordingly.
a
@kapa.ai In my case token endpoint requires application/x-www-form-urlencoded format. How can I specify this in the configuration?
k
A message from kapa.ai
To specify that the token endpoint requires the
application/x-www-form-urlencoded
format in your Airbyte OAuth configuration, you should set the
Content-Type
header in the
access_token_headers
section to
application/x-www-form-urlencoded
. By default, Airbyte sends the
access_token_params
as form-encoded data, so you only need to explicitly set the header if the API requires it. Here’s how you can do it:
Copy code
yaml advanced_auth:   auth_flow_type: oauth2.0   oauth_config_specification:     oauth_connector_input_specification:       consent_url: >-         https://yourconnectorservice.com/oauth/authorize?client_id={{client_id}}&redirect_uri={{redirect_uri}}&response_type=code&scope={{scope}}&state={{state}}       access_token_url: >-         https://yourconnectorservice.com/oauth/token       access_token_headers:         Content-Type: application/x-www-form-urlencoded         Authorization: "Basic {{ (client_id ~ ':' ~ client_secret) | b64encode }}"       access_token_params:         grant_type: "authorization_code"         code: "{{auth_code}}"         redirect_uri: "{{redirect_uri}}"
- The
access_token_headers
section sets the
Content-Type
to
application/x-www-form-urlencoded
. - The
access_token_params
will be sent as form-encoded data in the POST body, which matches the requirements for most OAuth 2.0 token endpoints. This approach is supported and documented in Airbyte’s YAML reference and OAuth configuration documentation, where you can specify custom headers for the token request, including
Content-Type
and
Authorization
as needed for your provider’s requirements [see YAML Reference](https://docs.airbyte.com/platform/next/connector-development/config-based/understanding-the-yaml-file/reference#/definitions/OAuthAuthenticator) and [Declarative OAuth 2.0](https://docs.airbyte.com/platform/next/connector-development/config-based/advanced-topics/oauth#advanced-case-client-secret-is-a-request-header-not-a-query-parameter). If you need to add additional custom headers, you can include them in the same
access_token_headers
section.