question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

msal.loginPopup fails to login when user has permissions w/o error message

See original GitHub issue

Core 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:

  1. msal.loginPopup fails to login when user has permissions w/o error message

What we saw:

  1. open the website in Chrome or Edge
  2. Click Login button
  3. sign in with popup dialog (msal.loginPopup())
  4. page gets refreshed
  5. useIsAuthenticated is still false
  6. 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

  1. Try to login with msal.loginPopup().
  2. Check whether token is saved in browser.
  3. 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:closed
  • Created a year ago
  • Comments:16 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
tnorlingcommented, Jul 25, 2022

@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.

1reaction
tnorlingcommented, Jul 21, 2022

@momoliu-msft Only the popup window gets redirected to your redirectUri and ideally that popup should get closed before the user has even noticed

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found