<@U04S8PLJWMT> - how can I best implement a custom...
# ask-ai
b
@kapa.ai - how can I best implement a custom self signed JWT authentication flow in your tool?
k
To implement a custom self-signed JWT authentication flow in Airbyte, you should use the
JwtAuthenticator
within your connector's YAML configuration. Airbyte provides a declarative way to define JWT authentication, allowing you to specify all necessary parameters for generating and signing JWTs, including custom headers and payloads. Here’s how you can set it up: 1. Use the JwtAuthenticator in your YAML: Define the authenticator block in your connector’s YAML file as shown below:
Copy code
yaml    authenticator:        type: JwtAuthenticator        secret_key: "{{ config['secret_key'] }}"        base64_encode_secret_key: true  # Set to true if your API requires base64 encoding      algorithm: RS256                # Use your required algorithm (e.g., RS256, HS256, etc.)      token_duration: 3600            # Token validity in seconds      header_prefix: Bearer           # Prefix for the Authorization header      jwt_headers:          kid: "{{ config['kid'] }}"          cty: "JWT"        additional_jwt_headers:          test: "{{ config['test']}}"        jwt_payload:          iss: "{{ config['iss'] }}"          sub: "sub value"          aud: "aud value"        additional_jwt_payload:          test: "test custom payload"
- Replace the placeholders with your actual configuration or map them to user-provided config fields. - You can customize
jwt_headers
and
jwt_payload
as needed for your API. 2. Reference in Documentation: For more details on each field and advanced options, see the [JwtAuthenticator Reference](https://docs.airbyte.com/connector-development/config-based/understanding-the-yaml-file/reference#/definitions/JwtAuthenticator). 3. When to Use Low-Code or Python CDK: If your JWT authentication flow requires more complex logic (e.g., request signing, multi-step authentication, or dynamic claims that cannot be expressed declaratively), you should implement your connector using the [low-code CDK](https://docs.airbyte.com/platform/connector-development/config-based/low-code-cdk-overview) or [Python CDK](https://docs.airbyte.com/platform/connector-development/cdk-python/) instead of the declarative YAML approach. This is necessary for APIs with highly custom authentication requirements that go beyond what the declarative
JwtAuthenticator
supports[Custom authentication methods](https://docs.airbyte.com/platform/next/connector-development/connector-builder-ui/authentication#custom-authentication-methods). Summary: For most self-signed JWT flows, the declarative
JwtAuthenticator
is sufficient and recommended. Only use the CDK if your use case cannot be handled declaratively. [JWT Authenticator Example](https://docs.airbyte.com/platform/next/connector-development/config-based/understanding-the-yaml-file/authentication#jwt-authenticator)