Repository navigation
[Identity] Aio Token Fix - #49533
[Identity] Aio Token Fix#49533
Conversation
|
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. |
|
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. |
|
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. |
There was a problem hiding this comment.
🟡 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) |
|
Kashif Khan (@kashifkhan) hi. Checking in if anything is happening with this. Cheers! |
l0lawrence
left a comment
There was a problem hiding this comment.
Do we want to add a cache size limit or timeout on entries? other than that lgtm

This PR fixes a regression in the async
OnBehalfOfCredentialwhere 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 requestfixes #49532