单一登录Azure AD,带有两个URL

时间:2015-07-02 15:32:26

标签: asp.net-mvc single-sign-on owin azure-active-directory openid-connect

假设我有2个网址指向一个网站,只使用网站绑定,例如:

productname1.company.com
productname2.company.com

我们的Web应用程序单点登录Azure Active Directory,而在Azure应用程序配置中,我已将:

productname1.company.com

用于SIGN-ON URL和REPLY URL:

enter image description here

如果用户来productname1.company.com,Azure单点登录身份验证就可以正常运行。

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

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

1 个答案:

答案 0 :(得分:2)

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

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

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;
           }
      }
   }