Skip to content
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

The acquireTokenSilent method is not performant when fetching token result from cache #2097

Open
aj-kueterman opened this issue May 9, 2024 · 2 comments

Comments

@aj-kueterman
Copy link

Describe the bug
The acquireTokenSilent method, used to fetch access tokens (including the ability to refresh tokens when needed) from the MSAL SDK is not performant enough for it's use case.

In our practical use of the MSAL library, we use an OkHttp Interceptor to append tokens to each request. These tokens are pulled from MSAL using acquireTokenSilent. Based on the documentation, this should mean on most requests that the access tokens are pulled from a cache and returned, except in the case where there is no valid access token. This works, but the time to fetch a token from the MSAL using this method is not performant - on the order of hundreds of milliseconds. When caching the access token locally instead we're able to fetch new tokens in less than 100ms.

Smartphone
Observed on multiple combinations of Android devices, operating systems, and browsers.
com.microsoft.identity.client:msal version 4.0.1.

Stacktrace
N/A

To Reproduce
Steps to reproduce the behavior:

  • Follow vanilla setup for MSAL Android project
  • Use acquireTokenSilent to fetch tokens on every network call
  • Make network calls as normal, and log the duration of each acquireTokenSilent call

Expected behavior
When access token is valid, calls to acquireTokenSilent should return tokens almost instantaneously.

Actual Behavior
When access token is valid, calls to acquireTokenSilent are returning tokens in between 100-1000ms.

Screenshots
Timing the time it takes to get a token from MSAL vs. pulling it from our local cache.

Using MSAL Local Cache
Screenshot 2024-05-09 at 11 50 43 AM Screenshot 2024-05-09 at 11 14 47 AM

Additional context
Related SO Post summarizing the same issue.

@negoe
Copy link
Contributor

negoe commented May 23, 2024

Hi @aj-kueterman, Thanks for your patience. Can you please provide some more details?

  1. Are you performing high number of transactions on your cache?
  2. Device details?
  3. Can you please try using the latest version of the MSAL and check if this solves your problem?

@aj-kueterman
Copy link
Author

Thank you for your response @negoe,

  1. Yes, we use acquireTokenSilent to fetch an access token on every request. Our app does heavily rely on network calls and we often make them in bunches (like during app startup).
  2. Happening across devices & emulators, but I'm testing on a Google Pixel 4a on Android 13.
  3. Yes, I'll run a test on the latest version and see if I see any performance improvements and report back.

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

No branches or pull requests

2 participants