feat(cdk): add api_token interpolation support to SessionTokenAuthenticator#885
Conversation
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>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
👋 Greetings, Airbyte Team Member!Here are some helpful tips and reminders for your convenience. 💡 Show Tips and TricksTesting This CDK VersionYou can test this version of the CDK using the following: # Run the CLI from this branch:
uvx 'git+https://github.com/airbytehq/airbyte-python-cdk.git@devin/1769528869-session-token-prefix#egg=airbyte-python-cdk[dev]' --help
# Update a connector to use the CDK from this branch ref:
cd airbyte-integrations/connectors/source-example
poe use-cdk-branch devin/1769528869-session-token-prefixPR Slash CommandsAirbyte Maintainers can execute the following slash commands on your PR:
|
Co-Authored-By: Ryan Waskewich <ryan.waskewich@airbyte.io>
PyTest Results (Full)3 835 tests 3 823 ✅ 10m 32s ⏱️ Results for commit a1f173f. ♻️ This comment has been updated with latest results. |
Co-Authored-By: Ryan Waskewich <ryan.waskewich@airbyte.io>
…essionTokenAuthenticator
This replaces the token_prefix approach with a more flexible interpolation approach using api_token template. Users can now use Jinja templates like 'Token {{ session_token }}' for Django REST Framework APIs.
Changes:
- Replace PrefixedTokenProvider with InterpolatedSessionTokenProvider
- Update schema to use api_token field instead of token_prefix
- Default api_token is '{{ session_token }}' for backward compatibility
- Update factory to always wrap with InterpolatedSessionTokenProvider
- Update tests to reflect new approach
Co-Authored-By: Ryan Waskewich <ryan.waskewich@airbyte.io>
📝 WalkthroughWalkthroughThis PR introduces support for configurable token templates in session-based authentication. A new Changes
Sequence Diagram(s)sequenceDiagram
participant App as Application
participant IST as InterpolatedSessionTokenProvider
participant STP as SessionTokenProvider
participant API as API Server
App->>IST: get_token()
activate IST
IST->>STP: get_token()
activate STP
STP->>API: POST /login (or equivalent)
API-->>STP: {token: "abc123"}
STP-->>IST: "abc123"
deactivate STP
IST->>IST: interpolate("Token {{ session_token }}", session_token="abc123")
IST-->>App: "Token abc123"
deactivate IST
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
Adds an
api_tokenfield toSessionTokenRequestApiKeyAuthenticatorthat allows flexible token formatting using Jinja interpolation. This enables support for APIs that require non-standard token formats, such as Django REST Framework APIs that expectAuthorization: Token <value>instead ofAuthorization: Bearer <value>.Changes:
api_tokenfield to the schema with default{{ session_token }}for backward compatibilityInterpolatedSessionTokenProviderclass that interpolates a template with the session token valueInterpolatedSessionTokenProvider(using default template whenapi_tokennot specified)InterpolatedSessionTokenProviderCloses #884
Updates since last revision
token_prefixapproach with interpolation approach per reviewer feedbackPrefixedTokenProviderwith simple string prefix toInterpolatedSessionTokenProviderwith Jinja templatetoken_prefixtoapi_tokenwith template syntax"Token {{ session_token }}","realm=xyz, token={{ session_token }}", etc.{{ session_token }}maintains backward compatibilityReview & Testing Checklist for Human
InterpolatedSessionTokenProvider, even whenapi_tokenis not specified (uses default{{ session_token }}). Verify this doesn't break existing connectors.session_tokenvariable is passed toInterpolatedString.eval()via kwargs. Confirm this works correctly with the CDK's Jinja evaluation.api_tokenshould work unchanged since it defaults to{{ session_token }}which just returns the raw token.Authorization: Token <value>format works correctly.Recommended test plan:
SessionTokenAuthenticatorwithapi_token: "Token {{ session_token }}"Token <session_token>rather than the raw token valueSessionTokenAuthenticatorwithoutapi_tokencontinue to workExample manifest snippet:
Notes
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.