OfficeDev / microsoft-teams-library-js

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

microsoftTeams.getContext callback is not called in authenticate window #975

Open dhoelzl opened 2 years ago

dhoelzl commented 2 years ago

In a Tab (with microsoftTeams already initialized) call the following:

microsoftTeams.authentication.authenticate({url: "<path to>/getteamscontext.html"});

getteamscontext.html:

<!DOCTYPE HTML>
<html>
  <body>
    <script src="https://statics.teams.cdn.office.net/sdk/v1.11.0/js/MicrosoftTeams.min.js" integrity="sha384-SCVF3m7OvDKnfAilUzYn2yozEvBeP8n/Oq0yTH8VUI70J4AzrqR70jzjdQ6DI8s2" crossorigin="anonymous"></script>
    <script>
      try {
        console.log("microsoftTeams object", microsoftTeams);
        microsoftTeams.initialize();
        microsoftTeams.getContext((context) => {
          console.log("microsoftTeams context", context);
        });
      } catch (e) {
        console.log(e);
      }
    </script>
  </body>
</html>

This will open a new authentication window and successfully print "microsoftTeams object" to the console of that window, but the getContext callback which should print "microsoftTeams context" is never being called.

When calling microsoftTeams.getContext in the tab (from which microsoftTeams.authentication.authenticate is called) it will work.

My used browser was Chrome 98.0.4758.102 (64 bit, official) but this also occurs in the native Teams client.

ghost commented 2 years ago

Hi dhoelzl! 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

sayali-MSFT commented 2 years ago

@dhoelzl -We are looking into this I will get back to you soon.

barrettlee commented 2 years ago

@dhoelzl, I am curious what is the scenario where this happens to you?

I am interested in the outcome because, I am seeing the same thing when I click "Visit site to install" while configuring my custom connector. It looks like the issue is when Teams has to open a new browser window as in authentication or configuring a connector, the Teams context is not sent or requested. None of the Teams SDK functions work in that scenario. I have been looking for a solution for a week and there are others here who are in the same situation.

This is unlike the configurable Tab configuration experience where it takes place inline/within the Teams UI and the context is there and the SDK works.

dhoelzl commented 2 years ago

@barrettlee What I want to do is performing the authentication of a tab to our web service and assign the Teams user to the user in our system after the authentication is complete. Therefore I need to read the UPN and the userID from the context in the authentication window. Alternatively I have tried to get that information via HTML5 messaging from the originating tab where I can access the context. This seems to work in the browser version of Teams but unfortunately the HTML5 messaging does not work in the native Teams client (When I do a postMessage to the opener window in the login window the event never reaches the tab - the exact same code however is working when running Teams in the web browser). I could pass the required data to the URL, but for security reasons this might not be the best idea.

It seems that the Teams JS API is completely "dead" when running inside the login window. None of any callbacks are called, I also cannot see any errors in the F12 console.

@dhoelzl, I am curious what is the scenario where this happens to you?

I am interested in the outcome because, I am seeing the same thing when I click "Visit site to install" while configuring my custom connector. It looks like the issue is when Teams has to open a new browser window as in authentication or configuring a connector, the Teams context is not sent or requested. None of the Teams SDK functions work in that scenario. I have been looking for a solution for a week and there are others here who are in the same situation.

This is unlike the configurable Tab configuration experience where it takes place inline/within the Teams UI and the context is there and the SDK works.

barrettlee commented 2 years ago

@dhoelzl , thats a clever work around. I may have to do a similar thing. By the way, the same issue is open here, with many others reporting the same : #680 and still no solution or explanation.

dhoelzl commented 2 years ago

@barrettlee Thanks for the info! I was told by a consultant from Microsoft that this should work in the authentication dialog, too, and if not I should record a bug.

@dhoelzl , thats a clever work around. I may have to do a similar thing. By the way, the same issue is open here, with many others reporting the same : #680 and still no solution or explanation.

sayali-MSFT commented 2 years ago

@dhoelzl - We are already checking it with engineering team and let you know if we get any updates.

Vimal-Karunamoorthy commented 2 years ago

We have been facing the same issue and our customers are not able to work because of this issue. Could you please let us know when this will be fixed? Thanks!

Meghana-MSFT commented 2 years ago

This issue has the same underlying cause as: https://github.com/OfficeDev/microsoft-teams-library-js/issues/629. Issue https://github.com/OfficeDev/microsoft-teams-library-js/issues/629 is triaged and prioritized to be fixed in June.

tiennguyen1293 commented 2 years ago

yes, this issue happening on Window OS not MacOS.

Microsoft Teams Version 1.5.00.14473. it was last updated on 29-Jun-22

abdulkareemnalband commented 1 year ago

We are also facing same issue, but on v2.5.0 It used to work on old vesion