使用两个 URL 的 Azure AD 单点登录

Single Sign On With Azure AD with two URLs

假设我有 2 个 url 指向一个网站,只需使用网站绑定,示例:

productname1.company.com
productname2.company.com

我们的 Web 应用程序单点登录到 Azure Active Directory,并且在 Azure 应用程序配置中,我输入了:

productname1.company.com

用于登录 URL 和回复 URL:

如果用户使用 productname1.company.com,Azure 单点登录身份验证将完美运行。

但是如果用户来到 productname2.company.com,它根本不起作用并重定向到 productname1.company.com.

的登录页面

我如何配置以使其与 productname2.company.com 一起使用,我正在使用 OWIN OpenIdConnect 通过 Azure AD 进行单点登录。

您可以添加 productname2.company.com 作为第二个回复 URL,然后让您的应用在重定向到 AAD 时指定适当的回复 URL。

您可以在用于配置 OWIN OpenID Connect 的 OpenIdConnectAuthenticationOptions 中的 RedirectToIdentityProvider 通知中执行此操作。

app.UseOpenIdConnectAuthentication(
   new OpenIdConnectAuthenticationOptions
   {
      Notifications = new OpenIdConnectAuthenticationNotifications()
      {
         RedirectToIdentityProvider = (context) =>
           {
              // This ensures that the address used for sign in and sign out is picked up dynamically from the request
              // this allows you to deploy your app (to Azure Web Sites, for example) without having to change settings
              // Remember that the base URL of the address used here must be defined as a Redirect URI in Ping beforehand.
              string appBaseUrl = context.Request.Scheme + "://" + context.Request.Host + context.Request.PathBase;
              string currentUrl = context.Request.Scheme + "://" + context.Request.Host + context.Request.Path;
              context.ProtocolMessage.RedirectUri = currentUrl;
              context.ProtocolMessage.PostLogoutRedirectUri = appBaseUrl;
           }
      }
   }