Please follow the issue template below. Failure to do so will result in a delay in answering your question.
[email protected] or @azure/[email protected]@azure/[email protected]@azure/[email protected]@azure/[email protected]@azure/[email protected]Important: Please fill in your exact version number above, e.g. [email protected].
React
When calling PublicClientApplication.prototype.logout(), sometimes it throws an exception
"Uncaught (in promise) SyntaxError: Unexpected token e in JSON at position 0"
The stack trace is minified on our end but it says
at JSON.parse
at t.getItem
at index.6b5ff599.js:2
at Array.forEach
at t.e.removeAccountContext
at t.e.removeAccount
at index.6b5ff588.js:2
at Array.forEach
at t.e.removeAllAccounts
at t.clear
Then after reloading the page, we get errors (probably due to inconsistent state after some failure in logging out):
"No_tokens_found: No tokens were found for the given scopes, and no authorization code was passed to acquireToken. You must retrieve an authorization code before making a call to acquireToken()"
"Uncaught (in promise) SyntaxError: Unexpected token e in JSON at position 0"
const publicClientApp = new PublicClientApplication({
auth: {
clientId: this.clientId,
authority: this.authority,
redirectUri: this.loginRedirectUri,
postLogoutRedirectUri: this.postLogoutRedirectUri
},
cache: {
cacheLocation: "localStorage",
storeAuthStateInCookie: isIEOrOldEdge // https://github.com/AzureAD/microsoft-authentication-library-for-js/issues/1188#issuecomment-634281307
},
system: {
loadFrameTimeout: 30000,
tokenRenewalOffsetSeconds: 60,
loggerOptions: {
loggerCallback: MsalAuthContext.msalLoggerCallback,
piiLoggingEnabled: false,
logLevel: LogLevel.Verbose
}
}
});
// Provide relevant code snippets here.
// For Azure B2C issues, please include your policies.
Logout should work and not thrown an error
@thoo1 could you please provide a code snippet of where you are using logout in your code?
Are there any values in your localStorage (that were not created by MSAL) that contain one of these strings in their key? For example, are you manually storing your access tokens in local storage?
@technical-boy we just call this.publicClientApp.logout();
We did have our own implementation of the implicit grant flow that we are trying to migrate off of, however I checked the keys we store and they do not contain "IdToken", "AccessToken", "RefreshToken"
This issue has not seen activity in 14 days. It will be closed in 7 days if it remains stale.
I also ran into this issue updating from V1 to V2
we've got the same issue.
we are migrating from adal to msal and have multiple apps running on the same domain.
some apps are still using adal and the issue is reproduced when you switch between apps and then try to logout
The reason of the issue is that format of id token value in local storage is different in adal (plain string) vs msal (json).
The linked PR (#2115) should fix this issue, it's in the review process at the moment.
so what's the solution for this, still happening in 2.4 in Safari. Thanks.
Daniel.
@DaniusLabs We believe the linked PR should fix this issue. It is slated for release in 2.5
Thanks @tnorling
My questions was more about what should I offer as means to logout to my current safari users?
When is 2.5 scheduled for?
Thank you.
@DaniusLabs I was actually corrected, this fix was just released today in version 2.4.1. Please give that a go and open a new issue if you continue to see this error. Thanks!
Thanks @tnorling
This seems to work now. Thank you very much!
Most helpful comment
I also ran into this issue updating from V1 to V2