I've been trying to implement a connector to inter...
# ask-ai
a
I've been trying to implement a connector to interact with the High Level CRM oauth api, which uses single-use refresh tokens. I've followed the docs and have come up with the following yaml:
Copy code
base_requester:
    type: HttpRequester
    url_base: https://services.leadconnectorhq.com/
    authenticator:
      type: OAuthAuthenticator
      grant_type: refresh_token
      client_id: "{{ config['client_id'] }}"
      client_secret: "{{ config['client_secret'] }}"
      refresh_token: "{{ config['refresh_token'] }}"
      access_token_name: access_token
      refresh_request_body:
        grant_type: refresh_token
        client_id: "{{ config['client_id'] }}"
        client_secret: "{{ config['client_secret'] }}"
        refresh_token: "{{ config['refresh_token'] }}"
      refresh_token_updater:
        refresh_token_name: refresh_token
        refresh_token_config_path:
          - refresh_token

...

spec:
advanced_auth:
      oauth_config_specification:
        complete_oauth_server_input_specification:
          required:
            - client_id
        complete_oauth_output_specification:
          required:
            - access_token
            - refresh_token
            - token_expiry_date
          properties:
            access_token:
              type: string
              path_in_connector_config:
                - access_token
              path_in_oauth_response:
                - access_token
            refresh_token:
              type: string
              path_in_connector_config:
                - refresh_token
              path_in_oauth_response:
                - refresh_token
            token_expiry_date:
              type: number
              path_in_connector_config:
                - token_expiry_date
              path_in_oauth_response:
                - expires_in
When I test it in the connector builder, it works fine. However, when I create a real source/connection with it, it manages to test the source successfully, then upon actually syncing the connection, it fails to authenticate with the refresh token. The other thing to note is that this worked until about a month ago, and then it simply stopped working. I'm not sure what happened, but we tried everything including a full re-install of airbyte. Am I missing something here?
k
Your YAML configuration for handling single-use refresh tokens in Airbyte appears to follow the documented approach: you are using the
refresh_token_updater
block to update the refresh token in the config after each use, which is required for APIs like High Level CRM that issue a new refresh token with every access token refresh. This is consistent with Airbyte's documentation for single-use refresh tokens, which states: - Enable
refresh_token_updater
so the connector updates its configuration with the new refresh token after each sync. - By default, the property
refresh_token
is used, but this can be customized. - You must specify an initial access token and its expiry date in the "Testing values" menu for testing in the builder, but this should not affect production syncs if the config is correct[Single-Use Refresh Tokens](https://docs.airbyte.com/platform/connector-development/connector-builder-ui/authentication#single-use-refresh-tokens). Given that your connector works in the builder but fails during actual syncs, and that it used to work but stopped about a month ago, here are some possible causes and troubleshooting steps based on the documentation: 1. Refresh Token Not Persisting The most common issue with single-use refresh tokens is that the updated refresh token is not being persisted to the source configuration after a sync. If the connector continues to use the old (now invalid) refresh token, authentication will fail. - Ensure that your Airbyte deployment has write access to persist updated configs. - Check Airbyte logs for errors related to config updates or file system permissions. 2. Config Path Consistency Double-check that the
refresh_token_config_path
in your YAML matches exactly where the refresh token is stored in your config. For example, if your config is nested, the path should reflect that (e.g.,
["credentials", "refresh_token"]
if under a
credentials
object). 3. Token Expiry Handling Make sure the
token_expiry_date
is being handled correctly. If the connector tries to use an expired access token without refreshing, or if the expiry is not being updated, it could cause failures. 4. Recent Airbyte Changes Since this worked until a month ago, check if your Airbyte version changed or if there were updates to the connector builder or platform that might have affected OAuth handling. Review the Airbyte changelog for any breaking changes related to OAuth or config persistence. 5. Testing vs. Production Differences The builder uses "Testing values" which may not reflect the actual runtime config. Ensure that the initial config for real sources includes a valid refresh token and that the config structure matches what your YAML expects. 6. API Changes If High Level CRM changed its OAuth implementation (e.g., response structure, required fields), your connector may need to be updated accordingly. Summary: Your YAML is structured according to Airbyte's documented approach for single-use refresh tokens. The most likely issue is that the updated refresh token is not being persisted to the source configuration after a sync, causing subsequent authentication attempts to fail. Double-check config paths, file system permissions, and recent changes in Airbyte or the API. If the problem persists, reviewing Airbyte logs for config update errors may provide more insight. If you need more specific troubleshooting, please provide relevant log excerpts from a failed sync, as the documentation does not cover all possible runtime issues. References: - [Single-Use Refresh Tokens](https://docs.airbyte.com/platform/connector-development/connector-builder-ui/authentication#single-use-refresh-tokens) - [Advanced Case: refresh token / single-use refresh token support](https://docs.airbyte.com/platform/1.8/connector-development/config-based/advanced-topics/oauth#advanced-case-refresh-token--single-use-refresh-token-support)
a
@kapa.ai Is there a way to persist refresh tokens using the python cdk?
k
A message from kapa.ai
Based on the available knowledge sources, the Python CDK (
Oauth2Authenticator
) supports refreshing access tokens using a refresh token, but it does not natively persist updated refresh tokens back to the connector configuration. This means that if your API issues a new refresh token each time (single-use refresh tokens), the CDK itself does not automatically update and persist the new refresh token for future syncs. Recent developments in Airbyte have introduced mechanisms to address this limitation, such as emitting control messages to update the configuration, and a
SingleUseRefreshTokenOauth2Authenticator
class. However, these features require platform support to actually persist the new refresh token, and as of the latest documentation, this is still being rolled out and may not be available in all Airbyte deployments yet. The official forum post confirms this limitation and ongoing work to support it natively in the platform[Forum Post: Handle expiring refresh tokens with oauth](https://discuss.airbyte.io/t/3275). Summary: - The Python CDK can refresh access tokens using a refresh token. - It does not natively persist new refresh tokens to the configuration. - Platform-level support for this feature is in progress but may not be fully available yet. If you need this functionality immediately, you may need to implement a workaround (such as using Airbyte state or custom logic), but this is not covered in the official documentation.
a
@kapa.ai Can you show me how I would store a refresh token in the connection state?
k
A message from kapa.ai
I'm sorry, but the knowledge sources do not contain explicit information or examples on how to store a refresh token in the connection state using the Airbyte Python CDK. The documentation and forum posts discuss the challenge of persisting new refresh tokens and mention ongoing work to support this natively in Airbyte, but they do not provide a concrete example or recommended approach for storing refresh tokens in the connection state within a custom connector implementation[Forum Post: Handle expiring refresh tokens with oauth](https://discuss.airbyte.io/t/3275). If you need to implement this, you may need to explore custom solutions, but this is not covered in the official documentation provided.
a
@kapa.ai How do you normally store information in the connection state?
k
A message from kapa.ai
In Airbyte's Python CDK, information is typically stored in the connection state using the
state
property provided by the
StateMixin
(or
CheckpointMixin
for some stream types). This property uses a getter and setter to serialize and deserialize the internal state of the stream. The state is usually represented as a dictionary and is used to track progress, such as the latest value of a cursor field for incremental syncs. Here’s a standard pattern for storing information (like a cursor value) in the connection state:
Copy code
python @property def state(self) -> Mapping[str, Any]:    return {self.cursor_field: str(self._cursor_value)}  @state.setter def state(self, value: Mapping[str, Any]):    self._cursor_value = value[self.cursor_field]
During the sync, you update the internal state (e.g.,
_cursor_value
) as you process records. The Airbyte platform then persists this state between syncs, allowing the connector to resume from where it left off in the next run. The state object can be structured to store any information needed to resume the sync, not just cursor values—for example, page numbers or timestamps, depending on your use case. For more details, see the documentation on [Incremental Streams](https://docs.airbyte.com/platform/1.8/connector-development/cdk-python/incremental-stream) and [Resumable Full Refresh Streams](https://docs.airbyte.com/platform/1.8/connector-development/cdk-python/resumable-full-refresh-stream#implementing-resumable-full-refresh-streams).
a
@kapa.ai Is there a way to save state from within a child of the HttpAuthenticator class?
k
A message from kapa.ai
I'm sorry, but the knowledge sources do not contain information about saving state from within a child of the
HttpAuthenticator
class in the Airbyte Python CDK. The available documentation and forum posts discuss how to manage state within streams (using the
state
property), but do not mention mechanisms for saving state directly from an authenticator or its subclasses. If you need this functionality, you may need to explore custom solutions, but this is not covered in the official documentation provided.
a
@kapa.ai Where can I find a reference to classes used in the python cdk?
k
A message from kapa.ai
You can find a reference to the classes used in the Python CDK in the [Airbyte CDK reference documentation](https://airbytehq.github.io/airbyte-python-cdk/airbyte_cdk.html), which is published automatically with each new CDK release. This documentation provides detailed information about the available classes and their usage in the Python CDK. For more guidance, see the "Getting Started" section in the official docs, which links directly to this reference[Connector Development Kit](https://docs.airbyte.com/platform/connector-development/cdk-python).
a
@kapa.ai Does get_updated_state work per-stream?
k
A message from kapa.ai
Yes,
get_updated_state
works per-stream. According to the Airbyte Python CDK documentation, the
get_updated_state
function helps the stream keep track of the latest state by inspecting every record output by the stream (as returned by the
Stream.read_records
method) and comparing it against the most recent state object. This allows sync to resume from where the previous sync last stopped, regardless of success or failure. The function typically compares the state object's and the latest record's cursor field, picking the latest one. This logic is scoped to each stream, so state is managed on a per-stream basis, not globally across all streams[Incremental Streams](https://docs.airbyte.com/platform/1.8/connector-development/cdk-python/incremental-stream).
a
@kapa.ai Is there a way to write to the connection config from a python cdk connector?
k
A message from kapa.ai
Based on the knowledge sources provided, there is no supported way to write to the connection config from a Python CDK connector. The Airbyte Python CDK does not expose an API or mechanism for a connector to directly mutate or persist changes to the connection configuration during runtime. Recent developments in Airbyte (such as emitting control messages for config mutation and the introduction of classes like
SingleUseRefreshTokenOauth2Authenticator
) are intended to address this limitation, but these features require platform-level support and are not yet fully available or documented for general use in the Python CDK. The official forum posts confirm that, as of now, persisting new refresh tokens or other config changes from within a connector is not natively supported and is still under development[Forum Post: Handle expiring refresh tokens with oauth](https://discuss.airbyte.io/t/3275). If you need to persist dynamic values (like a new refresh token), you may need to wait for full platform support or consider alternative approaches, but these are not covered in the current official documentation.