当前位置:  开发笔记 > 后端 > 正文

Azure AD B2C-多个子域

如何解决《AzureADB2C-多个子域》经验,为你挑选了1个好方法。

我可以将Azure Active Directory B2C设置为与多个子域一起使用吗?到目前为止,这是我所做的:

    设置一个B2C目录

    创建了一个Web应用程序:mytest.com-此应用程序中的身份验证和授权工作正常。

    我创建了另一个应用程序:subdomain.mytest.com-使用相同的Azure B2C Active目录

现在,我想要的是:当我登录“ mytest.com”时也要登录“ subdomain.mytest.com”

这可能吗 ?

我的应用程序是使用OpenId Connect的ASP.NET MVC应用程序。如果需要,我可以提供更多详细信息。

谢谢



1> 小智..:

使它起作用的行:

app.UseCookieAuthentication(new CookieAuthenticationOptions(){CookieDomain =“ .mytest.com”});

当我阅读本文时,我发现了这一点:https : //auth0.com/blog/2014/01/27/ten-things-you-should-know-about-tokens-and-cookies/(第3节)

public void ConfigureAuth(IAppBuilder app)
    {
        app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);

        app.UseCookieAuthentication(new CookieAuthenticationOptions() { CookieDomain = ".mytest.com"});

        var options = new OpenIdConnectAuthenticationOptions
        {
            ClientId = clientIdb2c,
            RedirectUri = redirectUri,
            PostLogoutRedirectUri = redirectUri,
            Notifications = new OpenIdConnectAuthenticationNotifications()
            {
                MessageReceived = (context) =>
                {

                    //AADB2C90091: The user has cancelled entering self-asserted information.
                    if (!string.IsNullOrEmpty(context.ProtocolMessage.ErrorDescription) && !context.ProtocolMessage.ErrorDescription.StartsWith("AADB2C90091:", StringComparison.OrdinalIgnoreCase))
                    {
                        if (context.ProtocolMessage.ErrorDescription.StartsWith("AADB2C99002", StringComparison.OrdinalIgnoreCase))
                        {
                            throw new SecurityTokenValidationException("User does not exist. Please sign up before you can sign in.");
                        }
                    }

                    return Task.FromResult(0);
                },
                RedirectToIdentityProvider = OnRedirectToIdentityProvider,
                AuthenticationFailed = AuthenticationFailed,
                SecurityTokenValidated = (context) =>
                {
                    //Create the logic to redirect here.
                    context.AuthenticationTicket.Properties.RedirectUri = "https://sub1.mytest.com";

                    return Task.FromResult(0);
                }
            },
            Scope = "openid offline_access",
            ResponseType = "id_token",

            // The PolicyConfigurationManager takes care of getting the correct Azure AD authentication
            // endpoints from the OpenID Connect metadata endpoint.  It is included in the PolicyAuthHelpers folder.
            ConfigurationManager = new PolicyConfigurationManager(
                String.Format(CultureInfo.InvariantCulture, aadInstance, tenant, "/v2.0", OIDCMetadataSuffix),
                new string[] { SignUpPolicyId, SignInPolicyId, ProfilePolicyId }),
        };

        app.UseOpenIdConnectAuthentication(options);
    }

推荐阅读
刘美娥94662
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有