<@U04S8PLJWMT> i am using the single use refresh t...
# ask-ai
o
@kapa.ai i am using the single use refresh token for oauth in my python connector. when i first initial my source it works and the oauth check is success but it doesn't save the values to the config for future use. it does set it in memory but not saving it for future runs this is my configuration. is there something wrong? i used the same configuration for other source that i created and everything worked
Copy code
basic_auth = BasicHttpAuthenticator(
        username=credentials["client_id"],
        password=credentials["client_secret"],
        config={},
        parameters={},
    )

    return SingleUseRefreshTokenOauth2Authenticator(
        connector_config=config,
        token_refresh_endpoint="https://app.gong.io/oauth2/generate-customer-token",
        client_id=credentials["client_id"],
        client_secret=credentials["client_secret"],
        access_token_config_path=("access_token",),
        refresh_token_config_path=("refresh_token",),
        token_expiry_date_config_path=("token_expiry_date",),
        refresh_request_body={
            "access_type": "offline",
        },
        refresh_request_headers=basic_auth.get_auth_header(),
    )
k
Your configuration for using a single-use refresh token in your Python connector appears structurally correct, but the issue you're experiencing—where the new refresh token is not persisted to the config for future runs—is a known challenge with single-use refresh tokens in Airbyte. Key Points from the Documentation: - For single-use refresh tokens, Airbyte connectors must update the configuration with the new refresh token after each token refresh. This is typically handled by enabling a "refresh token updater" or similar mechanism, which ensures the new refresh token is written back to the config and available for the next sync. - In the Python CDK, this functionality is provided by the
SingleUseRefreshTokenOauth2Authenticator
, but the platform must support persisting the updated config after a sync. If the platform only updates the token in memory and does not persist it, the next run will use the old (now invalid) refresh token, causing failures. Relevant Documentation: - The Airbyte documentation and forum posts confirm that for single-use refresh tokens, the connector must update its configuration with the new refresh token, and this requires platform support to persist the updated config. If the platform does not persist the new token, you will see exactly the behavior you describe: it works for the first run, but fails on subsequent runs because the new refresh token is not saved for future use [[Single-Use Refresh Tokens](https://docs.airbyte.com/platform/next/connector-development/connector-builder-ui/authentication#single-use-refresh-tokens)]. - There is an ongoing development in Airbyte to support this feature fully, as discussed in the forum: the platform needs to handle "control messages" from the connector to update the actor configuration during syncs. Until this is fully supported, the refresh token will not be persisted automatically [[Forum Post: Handle expiring refresh tokens with oauth](https://discuss.airbyte.io/t/3275)]. What You Can Do: - Double-check that your Airbyte platform version supports persisting config updates from the connector. If not, this is a platform limitation, not a problem with your connector code. - If you are using a recent version and it still does not persist, you may need to wait for the platform feature to be fully released and enabled. - As a workaround, some users have considered using Airbyte state or other mechanisms, but this is not the recommended or supported approach. Summary: Your configuration is correct for the connector side, but the persistence of the new refresh token depends on Airbyte platform support. If the platform does not persist the updated config, the connector will not work as expected with single-use refresh tokens. This is a known limitation and is being addressed by the Airbyte team [[Single-Use Refresh Tokens](https://docs.airbyte.com/platform/next/connector-development/connector-builder-ui/authentication#single-use-refresh-tokens)], [[Forum Post: Handle expiring refresh tokens with oauth](https://discuss.airbyte.io/t/3275)].
o
@kapa.ai how can i use the client id and client secret so it will be sent as a basic auth to the oauth request
k
A message from kapa.ai
To send the client ID and client secret as Basic Auth in the OAuth request in Airbyte, you should encode them as a base64 string in the format
client_id:client_secret
and set this value in the
Authorization
header as
Basic <base64-encoded-string>
. This is a common OAuth pattern and is supported in Airbyte's declarative OAuth configuration. Declarative Example: You can configure this in your connector's manifest by specifying the
access_token_headers
with the
Authorization
header set to the base64-encoded value. Here’s how you can do it:
Copy code
yaml access_token_headers:   Authorization: "{{ (client_id_value ~ ':' ~ client_secret_value) | b64encode | prepend('Basic ') }}"
This will send the header:
Copy code
Authorization: Basic <base64(client_id:client_secret)>
Reference from Airbyte Documentation: > Example with the header value encoded into
base64-string
> >
Copy code
> access_token_headers: >   Authorization: "{{ (client_id_value ~ ':' ~ client_secret_value) | b64encode | prepend('Basic ') }}" >
> [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) Python CDK Approach: If you are using the Python CDK, you can use the
BasicHttpAuthenticator
to generate the header and pass it to your OAuth authenticator’s
refresh_request_headers
parameter, as you are already doing:
Copy code
python basic_auth = BasicHttpAuthenticator(     username=credentials["client_id"],     password=credentials["client_secret"],     config={},     parameters={}, )  refresh_request_headers = basic_auth.get_auth_header()
Then, pass
refresh_request_headers
to your OAuth authenticator. This will ensure the client ID and secret are sent as Basic Auth in the OAuth request [[CDK Python HTTP Streams Authentication](https://docs.airbyte.com/platform/connector-development/cdk-python/http-streams#authentication)]. Summary: - Encode
client_id:client_secret
as base64 and set it in the
Authorization
header as
Basic <base64-string>
. - In declarative YAML, use the
access_token_headers
field as shown above. - In Python CDK, use
BasicHttpAuthenticator
and pass the header to your OAuth authenticator. Let me know if you need a full code example!