microsoftgraph / microsoft-graph-toolkit

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

[BUG] MGT4 prepscopes and custom apps/domains causes token corruption #3133

Open nickjisc opened 9 months ago

nickjisc commented 9 months ago

Describe the bug When using prepscopes to call graph endpoints whilst having a custom app prep scope already obtained can result in the token for the custom app/domain becoming invalid and cannot be re-requested. Reverting to v3 of MGT fixes the issues.

To Reproduce Steps to reproduce the behavior:

  1. Use a custom domain/app in a prepscope call
  2. prepscope with additional graph services
  3. attempt to call the custom domain/app api will result in a 401 error with the token being invalid

Expected behavior Should work as with v3 of MGT, that a prepscope doesn't invalidate the custom domain/app api endpoint

Environment (please complete the following information):

Providers.globalProvider = new Msal2Provider({
    clientId: "xxxxxx",
    loginType: LoginType.Redirect,
    redirectUri: window.location.protocol + "//" + window.location.host,
    scopes: ["user.read", "openid", "offline_access", "api://xxxxxxx/user"],
    customHosts: ["xxxxx", "service.powerapps.com", "api.bap.microsoft.com", "api.powerbi.com"]
});
Providers.client.api('some url').middlewareOptions(prepScopes(["api://xxxxxx/user"]))

then

Providers.client.api(`organization/${tenant!.id}`).middlewareOptions(prepScopes(["Directory.AccessAsUser.All",  "https://service.powerapps.com//User"])

and then back to the first call results in a 401 error

The same code (without the array brackets) works without issue in v3

nickjisc commented 5 months ago

still broken in the latest build