Reputation: 608
If a user is already signed into Teams and they visit a Task Module React app, is it possible for the app to obtain an OAuth token without requiring the user to sign in again? I'm able to obtain a token using the @microsoft/teams-js
node package, however this opens the browser and asks the user to sign in again which is bad user experience. Is there any way to avoid this? or will the app always require a user to sign in again
Upvotes: 0
Views: 622
Reputation: 2470
The user experience is a little different depending on which method you're using in the SDK to obtain the token.
Assuming you're using the latest SDK...
The preferred approach (where possible!) is to use microsoftTeams.authentication.getAuthToken()
- this will ask Teams to request a token from AAD on your behalf for the current user. This will invoke a popup if consent for the basic scopes are required (offline_access, profile, email, openid - from memory) but this should only happen the first time a user accesses your app (or if an Admin deletes the Enterprise App in their AAD tenant... which does happen). This requires a little AAD configuration to allow the Teams client to request tokens on behalf of your application.
The other method is to use microsoftTeams.authentication.authenticate()
- This will show a new window (because identity providers don't like iFrames) with your code that would typically use MSAL to redirect to the Microsoft login pages get a token in the same way you would for any SaaS solution. This method is also required if you want to get consent for additional scopes.
If you're seeing a login popup more than once (i.e. after the "first run" experience), I'm assuming you're using the second approach here?
Upvotes: 0