OfficeDev / microsoft-teams-library-js

JavaScript library for use by Microsoft Teams apps
https://docs.microsoft.com/microsoftteams/platform/
Other
426 stars 194 forks source link

Authentication pop up closes with failure in Teams desktop application #1304

Open cgvalayev opened 2 years ago

cgvalayev commented 2 years ago

Given: We have a Teams application with a static tab which loads our web app. Our web app uses @microsoft/teams-js version ^1.11.0. Immediately when user enters the tab with our web app we trigger authentication with the following code:

microsoftTeams.initialize(() => {
  microsoftTeams.getContext((context) => {
    microsoftTeams.authentication.authenticate({
      url: `https://messenger.chatgenie.io/auth-start`,
      width: 600,
      height: 535,
      successCallback: async (result) => {
        console.log(result)
        // success logic
      },
      failureCallback: (reason) => {
        const errorFromStorage = localStorage.getItem('chatgenie.error');
        console.log(errorFromStorage, reason);
      },
    });
  });
});

Our application domain is https://messenger.chatgenie.io

Authentication is implemented based on the documentation:

  1. microsoftTeams.authentication.authenticate redirects to https://messenger.chatgenie.io/auth-start
  2. Auth start page redirects to Auth0 which attempts to authenticate through Microsoft social connector with this redirect URI: https://messenger.chatgenie.io/auth-end
    1. Since user is already authenticated in Teams with his/her MS credentials they usually will just be prompted to select proper account and then redirect to https://messenger.chatgenie.io/auth-end
  3. Auth end page will collect authentication data and store it in localStorage and then fire microsoftTeams.authentication.notifySuccess(key); or microsoftTeams.authentication.notifyFailure('UnexpectedFailure');
  4. From here auth pop from Teams should close and the app will proceed with its logic

PROBLEM: When Teams auth pop up opens it gets to Microsoft auth screen and then immediately closes with CancelledByUser error in failureCallback

It seems to work perfectly ok for all the web users and some desktop users. But more and more we are getting complaints from Teams desktop (so far on Windows) users for which this is happening.

One client said that if they open the tab in a new window, microsoft authentication works successfully. Then refresh original tab and it also authenticates.

image
ghost commented 2 years ago

Hi cgvalayev! Thank you for bringing this issue to our attention. We will investigate and if we require further information we will reach out in one business day. Please use this link to escalate if you don't get replies.

Best regards, Teams Platform

ChetanSharma-msft commented 2 years ago

Hello @cgvalayev - Hope you are doing well!! Can you please try updating the Teams desktop client version and verify it once ?

cgvalayev commented 2 years ago

Hey @ChetanSharma-msft, just tried updating to the latest version and restarting teams, unfortunately didn't help. Here are some more findings from our troubleshooting:

Meghana-MSFT commented 2 years ago

This issue seems to be similar to https://github.com/OfficeDev/microsoft-teams-library-js/issues/629, we are checking the status of the fix. we will get back to you.

Meghana-MSFT commented 2 years ago

The issue has a proposed fix in Electron 16 based Teams. ETA for Mac is end of August. The current estimate for rollout on Windows is end of September.

Ref : https://github.com/OfficeDev/microsoft-teams-library-js/issues/1181#issuecomment-1179288178