Skip to content

[Identity] Aio Token Fix - #49533

Merged
Kashif Khan (kashifkhan) merged 6 commits into
Azure:mainfrom
kashifkhan:identity_aio
Oct 21, 2026
Merged

Kashif Khan (kashifkhan) merged 6 commits into
Azure:mainfrom
kashifkhan:identity_aio

Conversation

@kashifkhan

@kashifkhan Kashif Khan (kashifkhan) commented Oct 14, 2026 •

Copy link
Copy Markdown
Member

This PR fixes a regression in the async OnBehalfOfCredential where it stopped using cached tokens until the instance had exchanged its own user assertion. A new credential holding the same assertion therefore never used tokens another instance had cached, including with TokenCachePersistenceOptions, and every new instance made a network request

fixes #49532

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
10 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@jabbera

Copy link
Copy Markdown
Contributor

My robot thinks you are smarter than it: Recommendation: go with their fix. It's the owner's code, it removes the race, and it's stricter than ours. I'd close our PR in favor of theirs and post the cache-growth question on #49532 or their PR.

Your PR fixes the issue on my end.

@kashifkhan

Copy link
Copy Markdown
Member Author

Thank you for the update Mike Barry (@jabbera) . Im waiting on a few folks to get eyes on the PR before calling it good to go and push to prod asap so you are unblocked.

Copilot AI balanced review requested due to automatic review settings October 14, 2026 18:50

Copilot AI 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.

🟡 Changes recommended

Per-assertion namespaces leave permanent refresh-token and metadata entries, causing persistent caches to grow without bounds.

1 open finding
What changed in this PR

Fixes async OBO credentials so instances sharing an assertion can reuse cached tokens safely.

Changes:

  • Adds assertion-scoped cache namespaces.
  • Preserves tenant context during response caching.
  • Adds persistent-cache, isolation, concurrency, and subprocess tests.
File Description
azure/​identity/​_internal/​aad_client_base.py Implements assertion-scoped cache keys.
azure/​identity/​aio/​_internal/​aad_client.py Forwards tenant context to cache processing.
azure/​identity/​aio/​_credentials/​on_behalf_of.py Enables cross-instance access and refresh-token reuse.
tests/​test_obo_async.py Covers cache reuse and isolation scenarios.
tests/​obo_cache_process.py Tests cross-process persistent caching.
CHANGELOG.md Documents the regression fix.

🧠 Review effort: Balanced

# MSAL's account-based keys don't distinguish assertions for the same user. Use an OBO-only
# client namespace for cache storage, never on the wire, so both access and refresh tokens
# remain bound to the exact assertion, authority and requested tenant across instances.
return "{}:obo:{}:{}:{}".format(self._client_id, self._obo_assertion_hash, self._authority, tenant)
Copilot AI balanced review requested due to automatic review settings October 14, 2026 19:33

Copilot AI 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.

🔵 Needs a closer look

Authentication token-cache isolation and cross-process persistence changes warrant final human security review.

1 open finding

🧠 Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 14, 2026 21:07

Copilot AI 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.

🔵 Needs a closer look

Authentication isolation and persistent-cache changes require final human security review.

1 open finding

🧠 Review effort: Balanced

@jabbera

Copy link
Copy Markdown
Contributor

Kashif Khan (@kashifkhan) hi. Checking in if anything is happening with this. Cheers!

@l0lawrence l0lawrence left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we want to add a cache size limit or timeout on entries? other than that lgtm

@kashifkhan
Kashif Khan (kashifkhan) merged commit f8bcbd0 into Azure:main Oct 21, 2026
18 of 20 checks passed
@kashifkhan
Kashif Khan (kashifkhan) deleted the identity_aio branch October 22, 2026 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Development

Successfully merging this pull request may close these issues.

[azure-identity] aio.OnBehalfOfCredential doesn't read TokenCachePersistenceOptions cache from new instances in 1.26.0 (regression from 1.25.3)

6 participants