refactor: update OAuth token handling to use expires_in instead of ex… #1099
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Change OAuth Token Injection API to Use Standard
expires_inFormatProblem
The current OAuth token injection API expects
expires_at(an absolute timestamp) in the request body, which is non-standard. The OAuth 2.0 specification (RFC 6749) defines that token responses should includeexpires_inas the number of seconds until expiration, not an absolute timestamp. (Issue #1024)This forces API users to manually convert the standard
expires_invalue from OAuth providers into a customexpires_attimestamp:Solution
Update the OAuth token injection API to accept the standard
expires_informat (integer seconds) instead ofexpires_at(datetime string). This allows users to pass OAuth token responses directly to the Airweave API without manual conversion.Changes
1. Updated Input Schema (
backend/airweave/schemas/source_connection.py)Changed
OAuthTokenAuthenticationto useexpires_in:expires_at→expires_indatetime→intexpires_inis positive if provided2. Updated Service Logic (
backend/airweave/core/source_connection_service.py)Modified
_create_with_oauth_token()to storeexpires_indirectly in OAuth credentials:3. Regenerated OpenAPI Specification (
fern/definition/openapi.json)Updated the API documentation to reflect the new standard-compliant format.
Output Schema (Unchanged)
The output schema (
AuthenticationDetails) still returnsexpires_atas an absolute timestamp for display purposes. This provides:expires_inin seconds)expires_at)Testing
Verified the changes by:
/docsendpointOAuthTokenAuthenticationnow acceptsexpires_in(integer)Breaking Changes
Before:
{ "authentication": { "access_token": "...", "refresh_token": "...", "expires_at": "2025-11-11T20:17:54.670000" } }After:
{ "authentication": { "access_token": "...", "refresh_token": "...", "expires_in": 3600 } }Users will need to update their integration code, but this is a one-time change that simplifies their implementation going forward.
Benefits
References
Summary by cubic
Switch the OAuth token injection API to use expires_in (seconds) instead of expires_at (timestamp), aligning with OAuth 2.0 and removing manual conversion. This is a breaking change for clients that previously sent expires_at.
Written for commit 04204eb. Summary will update automatically on new commits.