Skip to content

feat: add caching for Token Vault connection token exchanges - #139

Merged
kishore7snehil merged 2 commits into
mainfrom
feat/token-vault-caching
Oct 22, 2026
Merged

kishore7snehil merged 2 commits into
mainfrom
feat/token-vault-caching

Conversation

@kishore7snehil

@kishore7snehil kishore7snehil commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

📋 Changes

This PR extends the token store added in the previous PR to also cache Token Vault exchanges. When a token store is configured, get_access_token_for_connection() reuses a previously exchanged connection token instead of hitting the token endpoint on every call.

✨ Features

  • Token Vault Caching: get_access_token_for_connection() caches exchanged tokens when token_store is set. Entries are keyed by tenant, client, caller sub and connection, so one caller or connection never gets another's token.
  • Fail-Open Store Handling: A store read or write failure is logged and the exchange proceeds normally. A malformed or expired entry counts as a cache miss.
  • No Caching Without sub: If the verified token has no usable sub claim, the cache is skipped with a warning.

🔧 API Changes

  • Added an optional keyword argument verified (VerifiedToken, default None) to get_access_token_for_connection(). Callers that have already verified the token (for example an MCP server) can pass it to avoid a second verification. When omitted and a token store is configured, the token is verified before any cache lookup.
  • get_access_token_for_connection() now raises VerifyAccessTokenError when a store is configured and the token fails verification, or when verified does not match the access token being exchanged.
  • The result now always includes expires_in alongside access_token, expires_at and scope.

📖 Documentation

  • Updated EXAMPLES.md with a Token Vault section covering a basic call and caching
  • Updated README.md and docs/TokenStorage.md to mention Token Vault caching

🧪 Testing

  • This change adds test coverage
  • This change has been tested on the latest version of the platform/language

Contributor Checklist

@kishore7snehil
kishore7snehil marked this pull request as ready for review October 6, 2026 06:55
@kishore7snehil
kishore7snehil requested a review from a team as a code owner October 6, 2026 06:55
@kishore7snehil
kishore7snehil force-pushed the feat/token-vault-caching branch from 64a62ec to bdbcef3 Compare October 7, 2026 14:54
@kishore7snehil
kishore7snehil changed the base branch from feat/obo-token-storage to feat/m2m-client-credentials October 7, 2026 14:54
Comment thread EXAMPLES.md Resolved
Comment thread src/auth0_api_python/api_client.py Resolved
Comment thread tests/test_api_client.py Resolved
Comment thread src/auth0_api_python/api_client.py Resolved
@kishore7snehil
kishore7snehil force-pushed the feat/token-vault-caching branch from bdbcef3 to 2abdc32 Compare October 8, 2026 04:07
@kishore7snehil
kishore7snehil force-pushed the feat/m2m-client-credentials branch 2 times, most recently from 6576276 to a9668aa Compare October 8, 2026 04:22
@kishore7snehil
kishore7snehil force-pushed the feat/token-vault-caching branch from 2abdc32 to eee148a Compare October 8, 2026 04:22
@kishore7snehil
kishore7snehil force-pushed the feat/m2m-client-credentials branch from a9668aa to 0d427d9 Compare October 12, 2026 09:59
@kishore7snehil
kishore7snehil force-pushed the feat/token-vault-caching branch 2 times, most recently from b8c3920 to d75882f Compare October 13, 2026 10:11
nandan-bhat
nandan-bhat previously approved these changes Oct 22, 2026
@kishore7snehil
kishore7snehil force-pushed the feat/m2m-client-credentials branch from 398a6bf to 9349c8f Compare October 22, 2026 06:41
@kishore7snehil
kishore7snehil force-pushed the feat/token-vault-caching branch from a941898 to e25abee Compare October 22, 2026 06:41
- Return scope on every cache hit so it matches a fresh result
- Include login_hint in the cache key
- Skip the cache for a non-string sub and treat wrongly typed stored entries as a miss
- Document the organization errors and fix the VerifiedToken usage in the examples
@kishore7snehil
kishore7snehil force-pushed the feat/m2m-client-credentials branch from 9349c8f to 75290da Compare October 22, 2026 06:52
@kishore7snehil
kishore7snehil force-pushed the feat/token-vault-caching branch from e25abee to e32b157 Compare October 22, 2026 06:52
Base automatically changed from feat/m2m-client-credentials to main October 22, 2026 07:19
@kishore7snehil
kishore7snehil dismissed nandan-bhat’s stale review October 22, 2026 07:19

The base branch was changed.

@kishore7snehil
kishore7snehil merged commit c8d366f into main Oct 22, 2026
7 checks passed
@kishore7snehil
kishore7snehil deleted the feat/token-vault-caching branch October 22, 2026 07:21
@kishore7snehil kishore7snehil mentioned this pull request Nov 11, 2026
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