訓練
認證
Microsoft Certified: Identity and Access Administrator Associate - Certifications
示範 Microsoft Entra ID 的功能,以現代化身分識別解決方案、實作混合式解決方案,以及實作身分識別治理。
With single sign-on (SSO) in Teams, app users have the advantage of using Teams to access tab apps. After logging in to Teams using Microsoft or Microsoft 365 account, app users can use your app without the need to sign in again. Your app is available to app users on any device with the access granted through Microsoft Entra ID.
Here's what you learn in this section:
The app users sign in to Teams using either personal Microsoft account or Microsoft 365 account. You can take advantage of this account and use SSO to authenticate and authorize the app users.
You can view here an example of user experience with SSO in a tab app:
Here's what your app users get with SSO experience:
Now, let's see what happens at the backend during runtime to achieve SSO experience within Teams.
Achieve SSO in a tab app by obtaining access token for the Teams app user who's logged in. This process involves the tab app client and server, Teams client, and Microsoft Entra ID. During this interaction, the app user must give consent for using Teams identity to obtain the access token in a multitenant environment.
The following image shows how SSO works when a Teams app user attempts to access the tab app:
# | Interaction | What's going on |
---|---|---|
1 | Tab app → Teams Client | The tab app makes a JavaScript call to getAuthToken() , which tells Teams to obtain an access token. |
2 | Teams Client → Microsoft Entra ID | Teams requests Microsoft Entra endpoint for the access token for the current app user based on Teams identity. |
3 | Microsoft Entra ID → Consent form | If the current app user is using your tab app for the first time, Teams displays request prompt to consent, if the app needs to access some protected data. The app user (or the administrator) must give consent to Teams for using the app user's Teams identity to obtain access token from Microsoft Entra ID. Alternately, there's a request prompt to handle step-up authentication such as two-factor authentication. |
4 | Microsoft Entra ID → Teams Client | Microsoft Entra ID sends the access token to the Teams Client. The token is a JSON Web Token (JWT), and its validation works just like token validation in most standard OAuth flows. Teams caches the token on your behalf so that future calls to getAuthToken() return the cached token. |
5 | Teams Client → Tab app client | Teams sends the access token to the tab app as part of the result object returned by the getAuthToken() call. |
6 | Tab app (between client and server) | The tab app parses the access token using JavaScript to extract required information, such as the app user's email address. The token returned to the tab app is both an access token and an identity token. |
For more information, see Add code to enable SSO in a tab app and Add code to enable SSO in your bot app.
重要
getAuthToken()
is valid only for consenting to a limited set of user-level APIs, such as email, profile, offline_access, and OpenId. It isn't used for other Graph scopes such as User.Read
or Mail.Read
. For suggested workarounds, see Extend your app with Microsoft Graph permissions.getAuthToken
fails for anonymous users as they aren't Microsoft Entra accounts.Tabs are Teams-aware web pages. To enable SSO in a webpage hosted inside a tab app, add Teams JavaScript client library and call microsoftTeams.initialize()
. After initialization, call microsoftTeams.getAuthToken()
to get the access token for your app.
You can enable SSO in Teams for all apps that support Microsoft Entra ID as an identity provider. In addition to using SSO for authenticating app users in a tab app, you can also use it to enable seamless access across Teams.
Some scenarios where you can use the SSO API to authenticate your app users are:
提示
You can also use the SSO API to authenticate app users in dialogs that embed web content.
To achieve SSO at runtime, configure your app to enable SSO for authenticating and authorizing app users.
This section describes the tasks involved in implementing SSO for a Teams app. These tasks are language- and framework-agnostic.
To enable SSO for a Teams tab app:
After the iOS 14 update, Apple has blocked the third-party cookie access for all apps by default. Therefore, the apps that use third-party cookies for authentication in their Channel or Chat tabs and Personal apps can't complete their authentication workflows on Teams iOS clients. To conform with Privacy and Security requirements, you must move to a token-based system or use first-party cookies for the user authentication workflows.
For Teams mobile, client versions that support SSO are:
For the best experience with Teams, use the latest version of iOS and Android.
Use the following step-by-step guides for enabling SSO for Teams app:
Here's a list of best practices:
getAuthToken()
only when you need an access token. You can call it when an app user accesses your tab app, or for using a particular function that requires app user validation.(window.parent!==window) => true
.訓練
認證
Microsoft Certified: Identity and Access Administrator Associate - Certifications
示範 Microsoft Entra ID 的功能,以現代化身分識別解決方案、實作混合式解決方案,以及實作身分識別治理。