【问题标题】:Azure Multi-Tenant Application with Windows Live ID Authentication具有 Windows Live ID 身份验证的 Azure 多租户应用程序
【发布时间】:2016-05-01 23:07:03
【问题描述】:

我们正在使用 Azure AD 多租户应用程序成功验证来自不同订阅的 Azure AD 用户,但无法验证 Windows Live ID 帐户。

为了验证 live ID 帐户,我们使用带有 Azure 访问控制服务 (ACS) 的 Windows Live ID 身份提供程序,它与 Azure AD 单租户应用程序一起工作,但我们正在努力跨订阅验证 Azure AD 用户,这些订阅只能是使用 Azure AD 多租户应用程序完成。

我们关注此博客https://msdn.microsoft.com/en-us/library/azure/dn486924.aspx,它适用于单租户应用程序,但是当我们尝试将 Azure AD 应用程序配置为多租户并使用 ACS 对其进行配置时,出现以下错误。 enter image description here 我们有什么方法可以验证 Windows Live ID 并使用 Azure 多租户应用程序?

【问题讨论】:

    标签: azure azure-active-directory


    【解决方案1】:

    您可以通过完全跳过 ACS 并在目录租户中配置 Microsoft 帐户来验证多租户应用程序中的 Microsoft 帐户(live id)用户。一个问题是,使用 Microsoft 帐户进行身份验证需要您通过在 URL 中实例化租户来完全指定身份验证端点。您不能使用 /common 端点,因为它依赖于用户的主租户,而 MSA 用户没有。

    【讨论】:

    • 我们正在构建一个应用程序,该应用程序能够通过多个 AD 跨订阅对用户进行身份验证。如果我们删除 /Common 端点并使用租户 ID,那么我们必须识别传入请求及其租户,以便我们使用租户 ID 并在其自己的租户上验证用户,除非我们有不同的 Url/Query 字符串,否则这是不可能的为每个租户。有没有其他方法可以使用 /Common 端点验证 Windows Live ID?
    • 正如我上面提到的,不。但是,没有什么能阻止您提供用户以某种方式指定他们想要使用的租户的体验,例如通过输入域。这将允许您即时创建租户身份验证 URL。
    【解决方案2】:

    您在帐户控制器中添加以下代码

    public void SignIn(string directoryName = "common")
        {
            // Send an OpenID Connect sign-in request.
            if (!Request.IsAuthenticated)
            {
                HttpContext.GetOwinContext().Environment.Add("Authority", string.Format(ConfigurationManager.AppSettings["ida:Authority"] + "OAuth2/Authorize", directoryName));
    
                HttpContext.GetOwinContext().Authentication.Challenge(new AuthenticationProperties { RedirectUri = "/" },
                   OpenIdConnectAuthenticationDefaults.AuthenticationType);
            }
        }
    

    并在你的 startup.auth.cs 中添加这个块

     app.UseOpenIdConnectAuthentication(
                new OpenIdConnectAuthenticationOptions
                {
                    ClientId = ClientId,
                    Authority = Authority,
                    TokenValidationParameters = new System.IdentityModel.Tokens.TokenValidationParameters
                    {
                        // we inject our own multitenant validation logic
                        ValidateIssuer = false,
                    },
                    Notifications = new OpenIdConnectAuthenticationNotifications()
                    {
                        RedirectToIdentityProvider = (context) =>
                        {
                            object obj = null;
                            if (context.OwinContext.Environment.TryGetValue("Authority", out obj))
                            {
                                string authority = obj as string;
                                if (authority != null)
                                {
                                    context.ProtocolMessage.IssuerAddress = authority;
                                }
                            }
                            if (context.OwinContext.Environment.TryGetValue("DomainHint", out obj))
                            {
                                string domainHint = obj as string;
                                if (domainHint != null)
                                {
                                    context.ProtocolMessage.SetParameter("domain_hint", domainHint);
                                }
                            }
                            context.ProtocolMessage.RedirectUri = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Path);
                            context.ProtocolMessage.PostLogoutRedirectUri = new UrlHelper(HttpContext.Current.Request.RequestContext).Action
                                ("Index", "Home", null, HttpContext.Current.Request.Url.Scheme);
                            //context.ProtocolMessage.Resource = GraphAPIIdentifier;
                            context.ProtocolMessage.Resource = AzureResourceManagerIdentifier;
                            return Task.FromResult(0);
                        },
    ...
    }
    

    当您单击“登录”时,询问“Azure AD 名称”。将该变量传递给 Account/SignIn 操作。如果用户出现在上述 Azure AD 中,则登录成功。

    【讨论】:

      猜你喜欢
      • 2018-04-05
      • 1970-01-01
      • 2015-05-27
      • 1970-01-01
      • 1970-01-01
      • 2021-02-12
      • 1970-01-01
      • 1970-01-01
      • 2023-02-09
      相关资源
      最近更新 更多