msal.loginPopup fails to login when user has permissions w/o error message
See original GitHub issueCore Library
MSAL.js v2 (@azure/msal-browser)
Core Library Version
^2.23.0
Wrapper Library
MSAL React (@azure/msal-react)
Wrapper Library Version
^1.3.2
Description
Two issues:
- msal.loginPopup fails to login when user has permissions w/o error message
What we saw:
- open the website in Chrome or Edge
- Click Login button
- sign in with popup dialog (msal.loginPopup())
- page gets refreshed
- useIsAuthenticated is still false
- Repeated attempts results in the same issue
This issue has become more serious recently.
Error Message
We do not see an exception or error returned. That’s the pain point.
Msal Logs
No logs available.
MSAL Configuration
{
auth:
{
"Instance": "https://login.microsoftonline.com/",
"TenantId": null,
"ClientId": null,
"ClientSecret": null,
"CallbackPath": "/signin-oidc"
}
cache: {
cacheLocation: "localStorage"
}
}
Relevant Code Snippets
Block 1:
<Button color='secondary' size='sm' onClick={() => msal.loginPopup()}>
Login
</Button>
Block 2:
const [isLoading, setLoading] = useState(false)
const isAuthenticated = useIsAuthenticated()
const setData = data => {
localStorage.setItem('Authorization', `Bearer ${data?.accessToken}`)
}
useEffect(() => {
if (isAuthenticated && !localStorage.Authorization && !isLoading && inProgress === InteractionStatus.None) {
setLoading(true)
msal
.acquireTokenSilent({
scopes: ['api://' + localStorage.ClientId + '/User.Read'],
account: account
})
.then(res => setData(res))
.catch(error => {
showError(error)
})
.finally(() => setLoading(false))
}
}, [isLoading, isAuthenticated, account, msal, inProgress])
Reproduction Steps
- Try to login with msal.loginPopup().
- Check whether token is saved in browser.
- Run useIsAuthenticated see if it returns true when there is token issued.
Expected Behavior
Successful login when the user has permissions or return some error message so we can know what happened.
Identity Provider
Azure AD / MSA
Browsers Affected (Select all that apply)
Chrome, Edge
Regression
No response
Source
Internal (Microsoft)
Issue Analytics
- State:
- Created a year ago
- Comments:16 (1 by maintainers)
Top Results From Across the Web
Microsoft Authentication Library (MSAL) loginPopup: Error The ...
Calling this code inside my application, I successfully log in using the popup window, but get the following error: ServerError: invalid_client: ...
Read more >Handle errors and exceptions in MSAL.js - Microsoft Entra
These errors result from things like calling a login method when login is already in progress, the user cancels the login, and so...
Read more >ClientAuthError: Error: could not resolve endpoints ... - GitHub
loginPopup() works without a parameter. From the error you posted I do see that this error could be thrown if the endPoint verification...
Read more >Microsoft Authentication Library for JavaScript (MSAL.js) - npm
When you login a user, you can pass in scopes that the user can pre consent to on login, however this is not...
Read more >Unable to get access token using msal
We have one webresource, we want to use microsoft graph api for that, we are getting access token using msal below in the...
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 FreeTop 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
Top GitHub Comments
@momoliu-msft You should be able to serve up static assets. Alternatively, you can ensure that your router preserves the hash while routing. The issue isn’t so much the presence of the router and more so that it is indeterminately redirecting to a static route which ends up removing the hash.
@momoliu-msft Only the popup window gets redirected to your redirectUri and ideally that popup should get closed before the user has even noticed