acquireTokenSilent does always call api even though token is already in cache
See original GitHub issueCore Library
MSAL.js v2 (@azure/msal-browser)
Core Library Version
“^2.17.0”
Wrapper Library
Not Applicable
Wrapper Library Version
None
Description
Revering to this documentations: token-lifetimes and aquire-token the library should only send a api request to azure if the token is expired or near to be expired.
I configured msal with cacheLocation: BrowserCacheLocation.SessionStorage
.
I call aquireTokenSilent on every api-call I do from my SPA to my backend. What I get is a call on /oauth2/v2.0/token
every time.
Error Message
API call to azure b2c on every call of acquireTokenSilent
Msal Logs
No response
MSAL Configuration
auth: {
clientId: clientConfig.clientId,
redirectUri: clientConfig.redirectUri,
authority: `https://${clientConfig.authoritySubDomain}.b2clogin.com/${clientConfig.authoritySubDomain}.onmicrosoft.com/${clientConfig.flow}`,
knownAuthorities: [
`${clientConfig.authoritySubDomain}.b2clogin.com`,
`${clientConfig.authoritySubDomain}.onmicrosoft.com`,
],
},
cache: {
cacheLocation: BrowserCacheLocation.SessionStorage
},
const SCOPES = ["openid", "offline_access", clientConfig.clientId];
Relevant Code Snippets
I call aquireTokenSilent by:
` public async getIDToken(): Promise<string | void> {
try {
const silentRequest: SilentRequest = {
account: this.account ? this.account : undefined,
scopes: SCOPES,
forceRefresh: false
};
const authenticationResult = await this.publicClientApplication.acquireTokenSilent(
silentRequest
);
return authenticationResult.idToken;
} catch (error) {
return await this.publicClientApplication.acquireTokenRedirect({
scopes: SCOPES,
});
}
}`
Reproduction Steps
- Call getIDToken() several times
Expected Behavior
Only one api request to azure b2c /oauth2/v2.0/token
is done
Identity Provider
Azure B2C Basic Policy
Browsers Affected (Select all that apply)
Chrome
Regression
No response
Source
External (Customer)
Issue Analytics
- State:
- Created 2 years ago
- Comments:13 (4 by maintainers)
Top Results From Across the Web
acquireTokenSilent making requests instead of using cache
Run this simple app which logs a user in and then requests an access token three times in a row with the same...
Read more >Does acquireTokenSilent needs to be called everytime I need ...
The AcquireTokenSilent will return the token it already has in cache if it is still valid or get a new one using refresh...
Read more >Acquire and cache tokens with Microsoft Authentication ...
Access tokens enable clients to securely call web APIs protected by Azure. There are several ways to acquire a token by using the...
Read more >acquiretokensilent refresh token - You.com | The AI Search ...
The AcquireTokenSilent will return the token it already has in cache if it is still valid or get a new one using refresh...
Read more >Solved: OAuth Refresh token has expired after 90 days
Solved: We have encountered an issue on our live environment: The Multi Factor Authentication does not work anymore. We try to authenticate using...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The issue has not been resolved. It is still not using the cache.
Hi @BenediktZoller, this is the behavior when you pass in the client id as part of the scopes, a fix of this is however being pushed today.