Skip to content

Commit 1557365

Browse files
feat(cdk): add token_prefix support to SessionTokenAuthenticator
This adds a token_prefix field to SessionTokenRequestApiKeyAuthenticator that allows prepending a custom prefix to the session token when injecting it into requests. This is useful for APIs that require a specific prefix before the token, such as Django REST Framework APIs that expect 'Authorization: Token <value>' format instead of the standard Bearer format. Changes: - Add token_prefix field to SessionTokenRequestApiKeyAuthenticator in schema - Create PrefixedTokenProvider wrapper class in token_provider.py - Update factory to wrap token provider with prefix when token_prefix is set - Regenerate Pydantic models from schema - Add unit tests for PrefixedTokenProvider Closes #884 Co-Authored-By: Ryan Waskewich <ryan.waskewich@airbyte.io>
1 parent 9b23860 commit 1557365

5 files changed

Lines changed: 148 additions & 62 deletions

File tree

airbyte_cdk/sources/declarative/auth/token_provider.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ def _refresh(self) -> None:
7171

7272
@dataclass
7373
class InterpolatedStringTokenProvider(TokenProvider):
74+
"""Provides a token by interpolating a string with config values."""
75+
7476
config: Config
7577
api_token: Union[InterpolatedString, str]
7678
parameters: Mapping[str, Any]
@@ -80,3 +82,18 @@ def __post_init__(self) -> None:
8082

8183
def get_token(self) -> str:
8284
return str(self._token.eval(self.config))
85+
86+
87+
@dataclass
88+
class PrefixedTokenProvider(TokenProvider):
89+
"""Wraps a TokenProvider and prepends a prefix to the token value.
90+
91+
This is useful for APIs that require a specific prefix before the token,
92+
such as Django REST Framework APIs that expect "Token <value>" format.
93+
"""
94+
95+
token_provider: TokenProvider
96+
prefix: str
97+
98+
def get_token(self) -> str:
99+
return f"{self.prefix}{self.token_provider.get_token()}"

airbyte_cdk/sources/declarative/declarative_component_schema.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2067,6 +2067,14 @@ definitions:
20672067
field_name: Authorization
20682068
- inject_into: request_parameter
20692069
field_name: authKey
2070+
token_prefix:
2071+
title: Token Prefix
2072+
description: 'A prefix to prepend to the session token when injecting it into requests. For example, use "Token " (with trailing space) for APIs that expect "Authorization: Token <token>".'
2073+
type: string
2074+
default: ""
2075+
examples:
2076+
- "Token "
2077+
- "Bearer "
20702078
SessionTokenRequestBearerAuthenticator:
20712079
title: Bearer Authenticator
20722080
description: Authenticator for requests using the session token as a standard bearer token.

0 commit comments

Comments
 (0)