New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Order scopes on save, and optimize the happy path for access token read #644
Conversation
Nice perf result. CC @pmaytak as the same strategy could be done in .NET |
now = time.time() | ||
refresh_reason = msal.telemetry.AT_ABSENT | ||
for entry in matches: | ||
for entry in self.token_cache._find( # It returns a generator |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing token_cache.find
to token_cache._find
makes this line no longer call the find
method on msal.token_cache.TokenCache
's subclasses, e.g. msal_extensions.token_cache.PersistedTokenCache.find
, but directly msal.token_cache.TokenCache._find
.
This causes all logic in msal_extensions.token_cache.PersistedTokenCache.find
being skipped:
This method contains 2 important functionalities:
- Load token cache from a file
- Handle concurrent situation
When a PersistedTokenCache
is provided to ConfidentialClientApplication
, as token cache is no longer loaded from a file, self._cache
becomes an empty dict when this line is called:
return self._cache.get(credential_type, {}).get(key, default) |
resulting in the token cache being bypassed.
PublicClientApplication
is not affected, as application.ClientApplication._find_msal_accounts
still uses the old find
.
for a in self.token_cache.find( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will be mitigated by MSAL EX AzureAD/microsoft-authentication-extensions-for-python#128
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you can take initiative to resolve that will be highly appreciated.
@Moazzem-Hossain-pixel , you are commenting on a topic that has already been implemented. There are some follow-ups in their own github issues linked above, and we are addressing them respectively. But the main change in the current topic is already stable. And our downstream partner - Azure CLI - has been unblocked by AzureAD/microsoft-authentication-extensions-for-python#127 If you are blocked by any specific issue, please add your comment into those linked issues, or even create a new issue to elaborate. Meanwhile, I'm locking this issue here. |
This PR currently contains 2 commits.
O(1)
vsO(n)
improvement.)