microsoftgraph / microsoft-graph-toolkit

Authentication Providers and UI components for Microsoft Graph 🦒
https://docs.microsoft.com/graph/toolkit/overview
Other
922 stars 285 forks source link

[BUG] Login control fails when refreshing the token after more than an hour of inactivity #3235

Open mpaliath opened 1 week ago

mpaliath commented 1 week ago

Describe the bug When the access token has expired, if the user comes back to the app, the Login component from @microsoft/mgt-react shows an error text TypeError: Cannot read properties of null (reading 'personImage') instead of the actual control.

To Reproduce Steps to reproduce the behavior:

  1. Use the login control to sign in using a personal Microsoft account.
  2. Note the login control now shows the signed in user.
  3. Do nothing in the app and wait for > 1 hour
  4. Refresh the page.
  5. See error.

Expected behavior The login control should show the signed in user

Screenshots If applicable, add screenshots to help explain your problem.

Environment (please complete the following information):

Additional context There was no problem with the v3 version I had been using. Problem started after the upgrade.

mpaliath commented 1 day ago

The issue seems to be with the code here

The issue happens when additionalScopes is an empty set and a new AuthenticationHandlerOptions is returned. Somewhere down the line this causes unexpected scopes to be used to make the query to graph api which returns a 4XX causing the problem here.

If I set isIncrementalConsentDisabled to true, the problem goes away. This workaround is good enough for me.

Providers.globalProvider = new Msal2Provider({ clientId: '5cf21436-2a20-447b-b222-77a1326409bb', scopes: [ 'profile', 'openid', 'User.Read' ], prompt: PromptType.LOGIN,
isIncrementalConsentDisabled: true, });