Azure active directory Azure AD B2C多租户应用程序

Azure active directory Azure AD B2C多租户应用程序,azure-active-directory,azure-api-apps,Azure Active Directory,Azure Api Apps,我一直在研究一种解决方案,将多租户api后端系统与多个B2C目录集成,其想法是每个租户拥有并管理自己的目录,因此我们的api后端系统需要添加到每个租户B2C目录中 我正在考虑扩展owin openID中间件,如下所述 另一种选择是设置我们自己的B2C目录,以集成我们租户的B2C目录 这可能吗?在Azure Active Directory的上下文中,OWIN OpenIDConnect中间件引用的客户端ID用于标识应用程序本身,而不考虑租约 对于多租户支持,如果您进入应用程序的“配置”部分,在

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

我正在考虑扩展owin openID中间件,如下所述

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


这可能吗?

在Azure Active Directory的上下文中,OWIN OpenIDConnect中间件引用的客户端ID用于标识应用程序本身,而不考虑租约

对于多租户支持,如果您进入应用程序的“配置”部分,在用于应用程序开发的广告下,您应该注意到一个标记为“应用程序是多租户”的选项,如屏幕截图所示

确保启用了多租户支持。启用多租户支持还有其他一些要求,在尝试启用该选项时,这些要求是显而易见的

此选项将允许其他租户的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);
                    }
                }
            });
资料来源:

禁用颁发者验证的原因是由于AAD的多租户应用程序中使用了公共网关,因此颁发者会根据正在进行身份验证的租户进行更改。事先必须有适当的发行人储备,以便与之进行比较