microsoftTeams.authentication.authenticate inconsistent behavior

%3CLINGO-SUB%20id%3D%22lingo-sub-1755371%22%20slang%3D%22en-US%22%3EmicrosoftTeams.authentication.authenticate%20inconsistent%20behavior%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1755371%22%20slang%3D%22en-US%22%3E%3CP%3EI'm%20using%20the%20following%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-javascript%22%3E%3CCODE%3EmicrosoftTeams.initialize()%0AmicrosoftTeams.authentication.authenticate(%7B%0A%20%20url%3A%20redirectUrl%2C%0A%20%20width%3A%20500%2C%0A%20%20height%3A%20500%2C%0A%20%20successCallback%3A%20()%20%3D%26gt%3B%20%7B%0A%20%20%20%20alert('success'%3B%0A%20%20%7D%2C%0A%20%20failureCallback%3A%20()%20%3D%26gt%3B%20%7B%0A%20%20%20%20alert('failed')%3B%0A%20%20%7D%2C%0A%7D)%3B%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThis%20works%20prefectly%20as%20expcted%20when%20using%20teams%20in%20the%20browser.%26nbsp%3B%20However%20in%20the%20Mac%20desktop%20client%2C%20when%20I%20first%20click%20sign%20in%20and%20run%20the%20above%20code%2C%20it%20launches%20an%20external%20browser%20instead%20of%20the%20popup.%26nbsp%3B%20Sometimes%20on%20the%202nd%20or%203rd%20attempt%20it%20will%20then%20open%20the%20popup.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20saw%20reference%20to%20waiting%20for%20initalization%20to%20complete%20with%20the%20following%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3EmicrosoftTeams.initialize(()%20%3D%26gt%3B%20%7B%0A%20%20%2F%2F%20Initialization%20complete%0A%7D)%3B%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBut%20this%20does%20not%20appear%20to%20work%20at%20all.%26nbsp%3B%20Any%20tips%20or%20things%20I%20may%20be%20overlooking%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1755371%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EDeveloper%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EHow-to%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMicrosoft%20Teams%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1773560%22%20slang%3D%22en-US%22%3ERe%3A%20microsoftTeams.authentication.authenticate%20inconsistent%20behavior%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1773560%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F822391%22%20target%3D%22_blank%22%3E%40matt131%3C%2FA%3E%26nbsp%3B%2C%20You%20need%20to%20wait%20for%20the%20initialization%20to%20complete%20before%20making%20the%20authenticate%20call.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CDIV%3E%0A%3CPRE%3EmicrosoftTeams.initialize(()%20%3D%26gt%3B%20%7B%0A%20%20microsoftTeams.authentication.authenticate(%7B%0A%20%20%20%20url%3A%20redirectUrl%2C%0A%20%20%20%20width%3A%20500%2C%0A%20%20%20%20height%3A%20500%2C%0A%20%20%20%20successCallback%3A%20()%20%3D%26gt%3B%20%7B%0A%20%20%20%20%20%20alert('success'%3B%0A%20%20%20%20%7D%2C%0A%20%20%20%20failureCallback%3A%20()%20%3D%26gt%3B%20%7B%0A%20%20%20%20%20%20alert('failed')%3B%0A%20%20%20%20%7D%2C%0A%20%20%7D)%3B%0A%7D)%3B%3C%2FPRE%3E%0A%3C%2FDIV%3E%3C%2FLINGO-BODY%3E
Highlighted
New Contributor

I'm using the following:

 

microsoftTeams.initialize()
microsoftTeams.authentication.authenticate({
  url: redirectUrl,
  width: 500,
  height: 500,
  successCallback: () => {
    alert('success';
  },
  failureCallback: () => {
    alert('failed');
  },
});

 

This works prefectly as expcted when using teams in the browser.  However in the Mac desktop client, when I first click sign in and run the above code, it launches an external browser instead of the popup.  Sometimes on the 2nd or 3rd attempt it will then open the popup. 

 

I saw reference to waiting for initalization to complete with the following:

 

 

microsoftTeams.initialize(() => {
  // Initialization complete
});

 

 

But this does not appear to work at all.  Any tips or things I may be overlooking?

1 Reply
Highlighted

@matt131 , You need to wait for the initialization to complete before making the authenticate call.

 

microsoftTeams.initialize(() => {
  microsoftTeams.authentication.authenticate({
    url: redirectUrl,
    width: 500,
    height: 500,
    successCallback: () => {
      alert('success';
    },
    failureCallback: () => {
      alert('failed');
    },
  });
});