【问题标题】:Azure AD B2C multitenants applicationsAzure AD B2C 多租户应用程序
【发布时间】:2016-03-05 12:51:45
【问题描述】:

我一直在研究一个将多租户api后端系统与多个B2C目录集成的解决方案,这个想法是每个租户都拥有并管理自己的目录,所以我们的api后端系统需要添加到每个租户中b2C 目录。

我正在考虑按照此处所述扩展 owin openID 中间件。

Active Directory B2C and OpenIdConnectAuthenticationMiddleware - Multitenant systems

另一种选择是设置我们自己的 B2C 目录来集成我们租户的 B2C 目录。

这可能吗?

【问题讨论】:

    标签: azure-active-directory azure-api-apps


    【解决方案1】:

    OWIN OpenIDConnect 中间件在 Azure Active Directory 的上下文中引用的客户端 ID 用于标识应用程序本身,而与租户无关。

    对于多租户支持,如果您进入应用程序的“配置”部分,在用于应用程序开发的 AD 下,您应该注意到一个标记为“APPLICATION IS MULTI-TENANT”的选项,如屏幕截图所示。 Multi-Tenant Option

    确保启用多租户支持。启用多租户支持还有其他要求,在尝试启用该选项时会很明显。

    此选项将允许其他租户的 AAD 同意使用您的应用程序。实际上,一旦租户的 AAD 全局管理员同意,这实际上会将您在 AAD 中注册的应用程序的引用添加到他们的 AAD,从而允许他们根据需要控制访问,而无需您进行任何更改。

    说到代码,您必须更改 OWIN 中间件以禁用颁发者的自动验证,并实施您自己的机制来验证颁发者(例如在租户初始注册时存储所有这些信息并检查所有未来租户登录针对最初存储的信息)。如下:

                app.UseOpenIdConnectAuthentication(
                new OpenIdConnectAuthenticationOptions
                {
                    ClientId = ClientId,
                    Authority = Authority,
                    TokenValidationParameters = new System.IdentityModel.Tokens.TokenValidationParameters
                    {
                        // instead of using the default validation (validating against a single issuer value, as we do in line of business apps), 
                        // we inject our own multitenant validation logic
                        ValidateIssuer = false,
                    },
                    Notifications = new OpenIdConnectAuthenticationNotifications()
                    {
                        // we use this notification for injecting our custom logic
                        SecurityTokenValidated = (context) =>
                        {
                            // retriever caller data from the incoming principal
                            string issuer = context.AuthenticationTicket.Identity.FindFirst("iss").Value;
                            string UPN = context.AuthenticationTicket.Identity.FindFirst(ClaimTypes.Name).Value;
                            string tenantID = context.AuthenticationTicket.Identity.FindFirst("http://schemas.microsoft.com/identity/claims/tenantid").Value;
    
                            if (
                                // the caller comes from an admin-consented, recorded issuer
                                (db.Tenants.FirstOrDefault(a => ((a.IssValue == issuer) && (a.AdminConsented))) == null)
                                // the caller is recorded in the db of users who went through the individual onboardoing
                                && (db.Users.FirstOrDefault(b =>((b.UPN == UPN) && (b.TenantID == tenantID))) == null)
                                )
                                // the caller was neither from a trusted issuer or a registered user - throw to block the authentication flow
                                throw new SecurityTokenValidationException();                            
                            return Task.FromResult(0);
                        }
                    }
                });
    

    来源:https://github.com/Azure-Samples/active-directory-dotnet-webapp-multitenant-openidconnect/blob/master/TodoListWebApp/App_Start/Startup.Auth.cs

    禁用颁发者验证的原因是因为 AAD 的多租户应用程序中使用了通用网关,因此颁发者会根据正在验证的租户而改变。必须事先有一些合适的发行人进行比较。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-12-29
      • 1970-01-01
      • 2020-08-26
      • 1970-01-01
      • 1970-01-01
      • 2017-07-07
      • 1970-01-01
      相关资源
      最近更新 更多