Skip to content

feat: Custom Token Exchange support#141

Merged
rmad17 merged 9 commits into
mainfrom
SDK-8920-cte
Jul 24, 2026
Merged

feat: Custom Token Exchange support#141
rmad17 merged 9 commits into
mainfrom
SDK-8920-cte

Conversation

@rmad17

@rmad17 rmad17 commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Changes

Features

  • Token exchange (AuthClient): custom_token_exchange and login_with_custom_token_exchange. Call custom_token_exchange to exchange a token for Auth0 tokens without touching the caller's session
    (service-to-service delegation, downstream API calls with a different audience/scope). Call login_with_custom_token_exchange to exchange a token and establish a full Auth0 session, same as completing
    /auth/callback.
  • Actor tokens (delegation): both methods accept actor_token/actor_token_type to represent a party acting on behalf of the subject; Auth0 surfaces this as the act claim on the response
    (custom_token_exchange) or persisted on the session user (login_with_custom_token_exchange).
  • Organization support: both methods accept an organization parameter to scope the exchange to a specific org.
  • Error handling: CustomTokenExchangeError is raised on exchange failure or invalid subject/actor token parameters, and is mapped to an HTTP 400 JSON response automatically once

API Changes

  • New public methods: AuthClient.custom_token_exchange, AuthClient.login_with_custom_token_exchange.
  • New exports from auth0_fastapi.errors: CustomTokenExchangeError, CustomTokenExchangeErrorCode (re-exported from auth0-server-python).

@rmad17 rmad17 self-assigned this Jul 9, 2026
@rmad17 rmad17 changed the title Sdk 8920 cte feat: Custom Token Exchange support Jul 9, 2026
@rmad17
rmad17 requested a review from kishore7snehil July 12, 2026 09:50
@rmad17
rmad17 marked this pull request as ready for review July 12, 2026 09:56
@rmad17
rmad17 requested a review from a team as a code owner July 12, 2026 09:56
Comment thread src/auth0_fastapi/auth/auth_client.py Outdated
await auth_client.handle_backchannel_logout(invalid_token)


class TestCustomTokenExchange:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests should go at the last. We should avoid adding new tests in middle of file until it's relevant to the existing class or function.

Comment thread src/auth0_fastapi/test/test_auth_client.py Outdated
)

@pytest.mark.asyncio
async def test_login_with_custom_token_exchange_passes_store_options_for_session_write(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These login-variant tests cover the happy path and store_options forwarding, but not two things the docs lean on: forwarding actor_token/actor_token_type through this method (the custom_token_exchange test above checks that, the login one doesn't), and the missing-response case that the README and examples call out as raising a ValueError.

Could we add a couple of small delegation tests here to lock both down?

Comment thread examples/CustomTokenExchange.md Outdated
Comment thread examples/CustomTokenExchange.md Outdated
Comment thread examples/CustomTokenExchange.md Outdated
@rmad17
rmad17 requested a review from kishore7snehil July 16, 2026 16:20

@kishore7snehil kishore7snehil left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@rmad17
rmad17 merged commit 3e703c9 into main Jul 24, 2026
9 checks passed
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