AadTokenProvider returns access token from old user.

Igor Grubyi 26 Reputation points
2021-04-29T14:38:30.847+00:00

We are developing Microsoft Sharepoint "Widgets" using javascript(React) and aadTokenProviderFactory to acquire tokens.

import { WebPartContext } from "@microsoft/sp-webpart-base";

async function getMSToken(context: WebPartContext) {
  const provider = await context.aadTokenProviderFactory.getTokenProvider();
  const token = await provider.getToken('https://graph.microsoft.com');

  return token;
}

This token is valid and everything works fine. But when switching users I receive a token from the old user. How to solve this issue and acquire tokens for the user that is currently signed in?

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
6,956 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
19,664 questions
{count} vote

Accepted answer
  1. sadomovalex 3,626 Reputation points
    2021-05-06T14:37:26.673+00:00

    getToken method has 2nd parameter called useCachedToken: aadtokenprovider. Try to pass false there:

    const token = await provider.getToken('https://graph.microsoft.com', false);  
    

0 additional answers

Sort by: Most helpful