asp.net - Azure AD B2C - 多个子域

标签 asp.net azure azure-active-directory openid-connect azure-ad-b2c

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

  1. 设置一个 B2C 目录
  2. 创建了一个网络应用程序:mytest.com - 此应用程序中的身份验证和授权工作正常。
  3. 我创建了另一个应用:subdomain.mytest.com - 它使用相同的 Azure B2C Active Directory

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

这可能吗?

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

谢谢

最佳答案

使其工作的线路:

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

关于asp.net - Azure AD B2C - 多个子域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34090387/

相关文章:

c# - 如何在 ASP.Net 中使用 URL 重写

msbuild - 在 Azure Project 上缩小并包含 js 和 css 文件

azure - SQL Server 代理在 Azure 上可用吗?

azure - 开发人员应如何为客户设置 Azure?

更改为不同的 Azure 订阅时,Azure PowerShell 脚本不起作用

c# - ASP.NET MVC 中的身份 cookie 身份验证

c#,查找String是否有图像链接并将其替换为html超链接

javascript - 试图在后面的代码中的按钮上执行 javascript 'confirm'

ssl - 在子域上使用 SSL 的 Azure 云服务

使用 AD B2C 进行守护程序应用程序的 Azure 函数身份验证