question

IgorGrubyi-3670 avatar image
1 Vote"
IgorGrubyi-3670 asked IgorGrubyi-3670 commented

AadTokenProvider returns access token from old user.

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-active-directoryazure-webapps
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I have the same problem. I cant retrieve current user token. Did anybody solve this problem?

0 Votes 0 ·

1 Answer

sadomovalex avatar image
0 Votes"
sadomovalex answered IgorGrubyi-3670 commented

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

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




· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thank you, it works!

0 Votes 0 ·