Forum Discussion

MrTimn's avatar
MrTimn
Copper Contributor
Nov 08, 2023

teamsfx-react@3.0.2 TeamsUserCredential.getToken results in error

The error I am getting when trying to get a teams access token:

 

Failed to get access token cache silently, please login first: you need login first before get access token.

 

Code that has the error:

// configure teamsfx-react

    const { loading, theme, themeString, teamsUserCredential } = useTeamsUserCredential({
        initiateLoginEndpoint: `${process.env.REACT_APP_INITIATE_LOGIN_ENDPOINT}/auth-start.html`,
        clientId: process.env.REACT_APP_AAD_APP_CLIENT_ID as string
    });
 
// calling getToken
const scopes = [
        "openid",
        "profile",
        process.env.REACT_APP_API_SCOPE as string,
    ];
 
// Throws the "please login first" error 
const token = await teamsUserCredential?.getToken(scopes)
 
The issue is only occurring on "New Teams" for Mac.  The same code works on "New Teams" on Windows.
 
Logging in solves the issue temporarily, if I close teams and open it again I am forced to login again.
I have been trying to figure out this issue for weeks.
 
 

Resources