{"id":11389,"date":"2022-08-31T08:00:26","date_gmt":"2022-08-31T15:00:26","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/?p=11389"},"modified":"2022-08-31T08:00:26","modified_gmt":"2022-08-31T15:00:26","slug":"account-linking-with-microsoft-teams-single-sign-on","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/account-linking-with-microsoft-teams-single-sign-on\/","title":{"rendered":"Account linking with Microsoft Teams single sign-on"},"content":{"rendered":"<p>Have you had trouble understanding how to use single sign-on (SSO)? Are you trying to link your identity system with Teams SSO for your Teams app? In this article, learn what Teams single sign-on means and take a look at a sample we\u2019ve built to help you use Teams SSO with your Identity Provider (IDP).<\/p>\n<p>Before we dive into these details, it\u2019s important to understand how to link user accounts between Teams and your app and Teams SSO.\nThe following resources are recommended to review:<\/p>\n<ol>\n<li><a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/active-directory\/manage-apps\/what-is-single-sign-on\">Learn about single sign-on in Azure Active Directory<\/a><\/li>\n<li><a href=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/lets-decode-single-sign-on-sso-in-microsoft-teams-tabs\/#:~:text=What%20is%20Teams%20SSO%3F,user%20to%20grant%20additional%20permissions.\">Learn about single sign-on in Teams<\/a><\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/en-us\/learn\/modules\/msteams-sso\/\">Complete this Teams SSO tutorial on Microsoft Learn<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/OfficeDev\/Microsoft-Teams-Samples\/tree\/main\/samples\/app-sso\/csharp\">Use this sample to deploy SSO in Teams<\/a><\/li>\n<li>(New!) <a href=\"https:\/\/github.com\/OfficeDev\/Microsoft-Teams-Samples\/tree\/main\/samples\/account-linking\/csharp\">Use our sample for deploying SSO in Teams with your app\/IDP and perform account linking<\/a><\/li>\n<\/ol>\n<p>You can also learn with <a href=\"https:\/\/aka.ms\/app-camp-account-linking\">this series of hands-on labs in Microsoft Teams App Camp<\/a>, which leads you through the experience of turning a simple web application into a Microsoft Teams application. As part of these labs, an account linking strategy is used to allow users to log in with Azure Active Directory SSO and still maintain user profiles and authorization from the original identity provider.<\/p>\n<h2>Teams SSO Overview<\/h2>\n<p>In short, Teams SSO is an identification model that enables users to login into a Microsoft Teams application with the same credentials they used when they signed into Microsoft Teams. The process is completely silent unless the application needs to ask the user to grant additional permissions. This diagram helps illustrate the underlying mechanism.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2022\/08\/Teams-SSO-blog-credentialing.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-11390\" src=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2022\/08\/Teams-SSO-blog-credentialing.png\" alt=\"diagram helps illustrate the underlying mechanism of Teams SSO\" width=\"936\" height=\"456\" srcset=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2022\/08\/Teams-SSO-blog-credentialing.png 936w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2022\/08\/Teams-SSO-blog-credentialing-300x146.png 300w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2022\/08\/Teams-SSO-blog-credentialing-768x374.png 768w\" sizes=\"(max-width: 936px) 100vw, 936px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>For a longer explanation of SSO, please refer to this article: <a href=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/lets-decode-single-sign-on-sso-in-microsoft-teams-tabs\/#:~:text=What%20is%20Teams%20SSO%3F,user%20to%20grant%20additional%20permissions.\">Let\u2019s decode: Single Sign-on in Microsoft Teams tabs &#8211; Microsoft 365 Developer Blog<\/a> and follow this Teams SSO tutorial on Microsoft Learn: <a href=\"https:\/\/docs.microsoft.com\/en-us\/learn\/modules\/msteams-sso\/\">Microsoft Teams \u2013 Authentication and Single Sign-on &#8211; Learn | Microsoft Docs<\/a><\/p>\n<h2>What are the challenges?<\/h2>\n<p><a href=\"https:\/\/docs.microsoft.com\/en-us\/microsoftteams\/platform\/tabs\/how-to\/authentication\/auth-aad-sso?tabs=dotnet\">Teams SSO<\/a>\u00a0offers a seamless experience for partners to build auth inside of Teams. However, Teams SSO can be difficult to implement when you (the person building the Teams app) need to link user accounts between Teams and your app&#8217;s identity systems.<\/p>\n<p>To get around this, we typically see partners try to use email addresses to match up user identities in their different systems. However, that generates several problems.<\/p>\n<p>Even if the emails are the same, there are a few problems. First, emails and User Principal Names (UPNs) can sometimes change. Second, most likely, the identity framework you&#8217;ve chosen won&#8217;t accept a simple email mapping and provide the user&#8217;s access tokens in their system. These access tokens are required because they are used to get permissions on the user&#8217;s behalf and are extremely important to keep secure. This path would also require you to change your own security architecture to allow special requests from your Teams apps.<\/p>\n<p>This is especially difficult if the user&#8217;s email in Teams is different than their email in your system. For example, the user\u2019s AAD email could be:\u00a0<a href=\"mailto:john@contoso.com\">john@contoso.com<\/a>, but the email that is registered with you is\u00a0<a href=\"mailto:john@gmail.com\">john@gmail.com<\/a>\u00a0or even\u00a0<a href=\"mailto:johnmatthews@contoso.com\">johnmatthews@contoso.com<\/a>. In both of these examples, the emails don\u2019t match up. The personal email address issue occurs frequently with apps that exist outside of enterprise scope.<\/p>\n<p>There&#8217;s an elegant solution to this problem.<\/p>\n<h2>An elegant solution<\/h2>\n<h3>Description<\/h3>\n<ol>\n<li>Get the user&#8217;s AAD access token &#8211; which can be done with a simple call (the beauty of SSO &#8211; review SSO Overview if this is unclear)<\/li>\n<li>Ask the user to sign into your chosen system or Identity Provider (IDP)<\/li>\n<li>Retrieve the access that your system or the Identity Provider provides<\/li>\n<li>Store that access token in a table associated with the user&#8217;s AAD identity<\/li>\n<\/ol>\n<p>Therefore, there are four parts to this solution:<\/p>\n<ul>\n<li>Logic to get a user&#8217;s Teams identity<\/li>\n<li>UI to prompt user to login to your app<\/li>\n<li>Logic to connect the user information from your IDP system to a user&#8217;s identity in Teams<\/li>\n<li>Table that contains: User&#8217;s Teams identity (GUID\/UUID) and the user&#8217;s access token from your IDP<\/li>\n<\/ul>\n<p>Now, whenever your Teams app needs to make a call, it can:<\/p>\n<ul>\n<li>View the user&#8217;s identity<\/li>\n<li>Check the table for the user&#8217;s IDP access token<\/li>\n<li>Call your app using that token<\/li>\n<\/ul>\n<h2>Next Steps<\/h2>\n<p>This content can help you get started with Teams SSO if you are new to it:<\/p>\n<ul>\n<li><strong>Try it today!<\/strong> <a href=\"https:\/\/github.com\/OfficeDev\/Microsoft-Teams-Samples\/tree\/main\/samples\/account-linking\/csharp\" target=\"_blank\" rel=\"noopener\">Here is a sample of this solution<\/a> to help you understand it better and get started<\/li>\n<li><a href=\"https:\/\/aka.ms\/app-camp-account-linking\" target=\"_blank\" rel=\"noopener\">Try these hands-on labs<\/a> in which you can migrate a web application with a non-Azure AD identity system to use Azure AD SSO with an account linking strategy.\n<a href=\"https:\/\/aka.ms\/app-camp-account-linking\">https:\/\/aka.ms\/app-camp-account-linking<\/a><\/li>\n<\/ul>\n<p>Have fun!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Learn what Microsoft Teams single sign-on means and take a look at a sample we\u2019ve built to help you use Teams SSO with your Identity Provider (IDP).<\/p>\n","protected":false},"author":99604,"featured_media":11396,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[5,128],"tags":[165,22,189,43],"class_list":["post-11389","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-microsoft-identity-platform","category-microsoft-teams","tag-azure-active-directory","tag-azure-ad","tag-single-sign-on","tag-sso"],"acf":[],"blog_post_summary":"<p>Learn what Microsoft Teams single sign-on means and take a look at a sample we\u2019ve built to help you use Teams SSO with your Identity Provider (IDP).<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/posts\/11389","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/users\/99604"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/comments?post=11389"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/posts\/11389\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/media\/11396"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/media?parent=11389"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/categories?post=11389"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/tags?post=11389"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}