Skip to content

Conversation

@subhankarmaiti
Copy link
Contributor

Implements Custom Token Exchange (RFC 8693) for auth0-server-python, enabling token exchange from external identity providers and legacy systems without browser redirects.

Changes

New Methods

  • custom_token_exchange() - Exchanges custom tokens for Auth0 tokens without session management (utility method)
  • login_with_custom_token_exchange() - Exchanges custom tokens AND establishes user session (high-level login method)

New Types

  • CustomTokenExchangeOptions - Configuration for token exchange
  • LoginWithCustomTokenExchangeOptions - Configuration for login with exchange
  • TokenExchangeResponse - Token exchange response with access/ID/refresh tokens
  • LoginWithCustomTokenExchangeResult - Login result with session state

Error Handling

  • CustomTokenExchangeError - Specific exception for token exchange failures
  • CustomTokenExchangeErrorCode - Error codes (INVALID_TOKEN_FORMAT, MISSING_ACTOR_TOKEN_TYPE, TOKEN_EXCHANGE_FAILED, INVALID_RESPONSE)

Use Cases

1. Backend Token Exchange (No Session)

response = await client.custom_token_exchange(
    CustomTokenExchangeOptions(
        subject_token="external-token",
        subject_token_type="urn:acme:mcp-token",
        audience="https://api.example.com"
    )
)

2. User Login via Token Exchange (With Session)

result = await client.login_with_custom_token_exchange(
    LoginWithCustomTokenExchangeOptions(
        subject_token="legacy-system-token",
        subject_token_type="urn:acme:legacy-token",
        audience="https://api.example.com"
    ),
    store_options={"request": request, "response": response}
)

@subhankarmaiti subhankarmaiti marked this pull request as ready for review February 3, 2026 07:34
@subhankarmaiti subhankarmaiti requested a review from a team as a code owner February 3, 2026 07:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants