OfficeDev / teams-toolkit

Developer tools for building Teams apps
Other
433 stars 171 forks source link

Teams tab app error - CP.UiRequiredError: Failed to get access token cache silently, please login first: you need login first before get access token. #11876

Open umalhotra86 opened 1 week ago

umalhotra86 commented 1 week ago

Describe the bug Teams tab application is failing to load. This error is observed in console - Uncaught (in promise) CP.UiRequiredError: Failed to get access token cache silently, please login first: you need login first before get access token.

To Reproduce Steps to reproduce the behavior:

  1. Deploy the teams react application to azure. Manifest is attached.
  2. Launch application in desktop/web.
  3. UI fails to load due to the error described above.

Expected behavior Access token will be retireved and API calls to web API's hosted on azure will succeed.

Screenshots image

OS

Node version/ Script references

KennethBWSong commented 1 week ago

Hi @umalhotra86 Thank you for using Teams Toolkit. UiRequiredError is expected when user have not consented permission for the app. When getting this error, you need to popup login page for user to consent using the following lines:

await teamsUserCredential!.login(["YOUR_PERMISSION"]);
umalhotra86 commented 6 days ago

@KennethBWSong Already taking care of this in the logic. Before requesting for token, we ensure that login call has succeded. Shared below the function that ensures this.

public validateToken = async (scopes: any) => { try { await teamsUserCredential?.getToken(scopes); } catch (error) { await teamsUserCredential?.login(scopes); } };