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.
 
 

9 Replies

    • shabbirdhangot's avatar
      shabbirdhangot
      Copper Contributor

      We are also facing similar issue with our production application. Kindly provide urgent resolution for the issue. I have reported issue to TeamsFx side as well. Following is Github issue link for the same: https://github.com/OfficeDev/TeamsFx/issues/10379

    • MrTimn's avatar
      MrTimn
      Copper Contributor
      I am using New Teams on Mac:
      Version: 23285.3805.2505.9215
      ClientVersion: 50/23101227708
      • Sayali-MSFT's avatar
        Sayali-MSFT
        Icon for Microsoft rankMicrosoft
        MrTimn -We are checking this issue with the internal team; we will let you know once we have any update.
    • MrTimn's avatar
      MrTimn
      Copper Contributor
      My application is using Application Insights, so I may be able to provide more information.
      Let me know if there is anything I could provide that would help you troubleshoot the issue.
      Thanks

Resources