05-21-2020 02:45 PM
05-21-2020 02:45 PM
We're developing an app for Teams and found a problem where the first time we call microsoftTeams.authentication.authenticate() in the Desktop app (both Mac and Windows) it opens the specified url in an external browser window/tab instead of a pop-up window. When this happens, authentication gets stuck and can't complete, so the tab never closes.
It's nearly impossible for us to debug why the external browser tab can't complete the authentication - the desktop app blocks our local builds, and also seems to remove debugger statements when we run from a dev deployment. The bug is not reproducible when using the Teams web app (which does work with our local builds). But this is probably beside the point.
When the external browser tab problem happens, there is an error message in the console for the Teams tab that made the authenticate() call as follows: Error during Teams authentication: Error: Unable to send AtomFrameHostMsg_Message_Sync. Full stack info:
Uncaught (in promise) Error: Unable to send AtomFrameHostMsg_Message_Sync
at EventEmitter.ipcRenderer.sendSync (<anonymous>:1717:18)
at Object.exports.invokeSync (<anonymous>:1692:41)
at Object.<anonymous> (<anonymous>:3229:22)
at Object.require.34../../common/atom-binding-setup (<anonymous>:3374:4)
at o (<anonymous>:2:273)
at r (<anonymous>:2:439)
Now, the interesting thing is that any microsoftTeams.authentication.authenticate() call after this works correctly - it opens in a pop-up window and authentication works without problems. Refresh the page and we're back to square one - first authenticate() behaves incorrectly but subsequent calls work as expected.
06-22-2020 12:42 PMSolution
The problem was that .initialize() method is not a synchronous operation. Digging into the API docs shows that .initialize() takes a callback function as a parameter. So wrapping this in a promise and chaining the authentication call to happen afterward fixed the problem.