Closed spavithra5 closed 3 years ago
I experienced a similar issue: #2403
You may find that the various redirect methods return null
with the expectation that the response doesn't matter because the page is redirecting anyway. However, there is usually a slight delay while the redirect happens and your script will continue to execute with MSAL in an unexpected state. Long story short, try something like this:
log('Authenticating via redirect...');
return _authApp.loginRedirect(request).then(
// loginRedirect sometimes returns too quickly and you see erroneous state on the page before the browser
// redirects. This is to guard against that spurious condition
() => new Promise((resolve) => setTimeout(resolve, 60000))
);
@spavithra5 Are you calling login()
or getTokenRedirect()
when the page loads, or as a result of some user interaction? I think what may be happening here is that one of these APIs is being called before the handleRedirectPromise()
has a chance to finish, which is causing the app to throw this error. If you can wait until handleRedirectPromise()
has resolved you should not have these errors anymore.
@patrick-jones and @pkanher617 Thank you for your response. I went through the code, once again, and there was a place where login is called again before the handleRedirectPromise is resolved. For now, i have commented it out. So this error is not occuring. But ideally for our application, during the login itself, API is called, I am not sure how to handle that scenario because in React within the Componentwillmount and componentdidmount, API is called, so ideally it's being called before the token is obtained through login, so i get the "Interaction in progress error" . Any suggestions on how to handle it?
It depends on how you are calling the API, but ideally you could do
handleRedirectPromise().then(resp => {
if (resp) {
// use resp.accessToken to make the API call
} else {
// use getAccount APIs to check if your account is there
// if you have an account, call acquireTokenSilent() to get the token and renew it if it is expired, then use the token in the API call
// if you do not have an account, you are not signed in and should present a login screen or kick off login automatically
}
});
I highly recommend taking a look at the msal-react library as it takes care of a lot of this for you. Reading through the docs for msal-browser and msal-react may also help.
Thank you for your kind response. I will try this. But in the npm website it's mentioned that msal-react is under development. We do not recommend using this in a production environment yet. So is it fine to use it?
This issue has not seen activity in 14 days. If your issue has not been resolved please leave a comment to keep this open. It will be closed in 7 days if it remains stale.
This issue has been closed due to inactivity. If this has not been resolved please open a new issue. Thanks!
Library
msal@1.x.x
or@azure/msal@1.x.x
@azure/msal-browser@2.x.x
@azure/msal-node@1.x.x
@azure/msal-react@1.x.x
@azure/msal-angular@0.x.x
@azure/msal-angular@1.x.x
@azure/msal-angular@2.x.x
@azure/msal-angularjs@1.x.x
Framework
Description
I am following the sample in https://github.com/Azure-Samples/ms-identity-b2c-javascript-spa Everytime i login, i get this error message. When i refresh the page it's working as expected.
Error Message
MSAL Configuration
Reproduction steps
1) Login to ADB2C 2) Error occurs in console 3) 3) Refresh the page, works as expected
Expected behavior
Identity Provider
Browsers/Environment
Regression
Security
Source