I'm building a custom connector through .yaml how ...
# ask-ai
t
I'm building a custom connector through .yaml how can I access the SessionToken that's stored as a BearerToken?
u
To access the SessionToken that's stored as a BearerToken in your custom connector, you can use the
SessionTokenAuthenticator
object in your YAML file. This object describes the request to perform to obtain a session token to perform data requests. The response body is expected to be a JSON object with a session token property. Here is an example of how you can define it in your YAML file:
Copy code
yaml login_requester:    type: HttpRequester   url_base: "<https://my_api.com>"   path: "/login"   authenticator:      type: BasicHttpAuthenticator     username: "{{ config.username }}"     password: "{{ config.password }}" session_token_path:    - "access_token"
In the above example,
session_token_path
is the path in the response body returned from the login requester to the session token. You can replace
"access_token"
with the actual path to your session token in the response body. Once you have the session token, you can use it as a Bearer token for authenticating your requests. You can use the
BearerAuthenticator
object for this purpose. Here is an example:
Copy code
yaml authenticator:     type: BearerAuthenticator     api_token: "{{ config['api_key'] }}"
In the above example,
api_token
is the token to inject as request header for authenticating with the API. You can replace
"{{ config['api_key'] }}"
with the actual session token that you obtained. For more information, you can refer to the [Airbyte documentation](https://docs.airbyte.com/connector-development/config-based/understanding-the-yaml-file/reference#/definitions/SessionTokenAuthenticator) on
SessionTokenAuthenticator
and
BearerAuthenticator
. Please note that the actual implementation may vary depending on the specifics of your API and how it handles session tokens and bearer tokens.
t
@kapa.ai I need to know where the session token is stored when I use the SessionTokenRequestBearerAuthenticator method for data request authentication
u
The SessionTokenRequestBearerAuthenticator method is used to authenticate requests using the session token as a standard bearer token. However, the specific location where the session token is stored is not explicitly mentioned in the provided knowledge sources. Typically, in the context of Airbyte's Session Token Authenticator, the session token is fetched from the session token endpoint in your API and reused until it expires. Once the session token is retrieved, your connector will reuse that token until it expires, at which point it will retrieve a new session token using the configured settings. For example, in the case of Metabase, the
/api/session
response looks like
{&quot;id&quot;:&quot;<session-token-value>&quot;}
, so the value here would simply be
id
. This indicates that the session token is stored in the response body of the session token retrieval request. However, for a more specific answer related to your use case, you may need to refer to the documentation of the specific API you are working with or the specific connector's documentation in Airbyte. For more information, you can refer to the following sources: - [Session Token Authenticator](https://docs.airbyte.com/connector-development/connector-builder-ui/authentication#session-token) - [Connector Builder UI Authentication](https://docs.airbyte.com/connector-development/connector-builder-ui/authentication#configuration) - [SessionTokenRequestBearerAuthenticator](https://docs.airbyte.com/connector-development/config-based/understanding-the-yaml-file/reference#/definitions/SessionTokenRequestBearerAuthenticator)
t
@kapa.ai is this session token stored in a variable that I can access globally in my .YAML file?
u
A message from kapa.ai
u
The session token is not directly stored in a variable that you can access globally in your .YAML file. Instead, it is dynamically fetched and used by the connector during runtime based on the configuration you provide in the .YAML file. In the SessionTokenAuthenticator configuration, you specify the
login_requester
and
session_token_path
. The
login_requester
describes the request to perform to obtain a session token, and the
session_token_path
is the path in the response body from the login requester to the session token. Here is an example of how it might look in your .YAML file:
Copy code
yaml login_requester:   type: HttpRequester   url_base: "<https://my_api.com>"   path: "/login"   authenticator:     type: BasicHttpAuthenticator     username: "{{ config.username }}"     password: "{{ config.password }}" session_token_path:   - "access_token"
In this example, the connector will make a request to
<https://my_api.com/login>
with the provided username and password, and then extract the session token from the
access_token
field in the response. For more information, you can refer to the [SessionTokenAuthenticator documentation](https://docs.airbyte.com/connector-development/config-based/understanding-the-yaml-file/reference#/definitions/SessionTokenAuthenticator).