OfficeDev/teams-toolkit

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

Closed this issue · 5 comments

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

  • OS: Windows 10

Node version/ Script references

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"]);

@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); } };

@umalhotra86 As synced in another thread, please use lower version @microsoft/teamsfx and @microsoft/teamsfx-react to workaround this issue. Feel free to let us know if you have further question.

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 7 days. It will be closed if no further activity occurs within 3 days of this comment. If it is closed, feel free to comment when you are able to provide the additional information and we will re-investigate.

Due to lack of details for further investigation, we will archive the issue for now. In case you still have following-up questions on this issue, please always feel free to reopen the issue by clicking ‘reopen issue’ button below the comment box. We will get back to you as soon as possible.