如何在 azure ad scim 配置中支持多个租户和秘密令牌

Ric*_*erg 6 c# provisioning azure-active-directory asp.net-core scim2

我正在尝试为我们的 Saas 产品创建 Azure AD 配置(使用 scim2)。我希望多个客户能够连接到他们的 Azure AD 租户。

微软在这里有参考代码: https: //github.com/AzureAD/SCIMReferenceCode

但是,设置为仅允许一个租户,并且不使用您在天蓝色广告中设置的“秘密令牌”。即使评论明确指出秘密令牌不应留空以供生产。

这是参考项目中的重要代码

// Leave the optional Secret Token field blank
            // Azure AD includes an OAuth bearer token issued from Azure AD with each request
            // The following code validates the Azure AD-issued token
            // NOTE: It's not recommended to leave this field blank and rely on a token generated by Azure AD. 
            //       This option is primarily available for testing purposes.
            services.AddAuthentication(options =>
            {
                options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
            })
            .AddJwtBearer(options =>
            {
                options.Authority = this.configuration["Token:TokenIssuer"];
                options.Audience = this.configuration["Token:TokenAudience"];
                options.Events = new JwtBearerEvents
                {
                    OnTokenValidated = context =>
                    {
                        // NOTE: You can optionally take action when the OAuth 2.0 bearer token was validated.

                        return Task.CompletedTask;
                    },
                    OnAuthenticationFailed = AuthenticationFailed
                };
            });
Run Code Online (Sandbox Code Playgroud)

使用该代码,假设 Token:TokenIssuer 设置为https://sts.windows.net/ <tenant_id>/ ,其中tenant_id 是实际租户 ID,TokenAudience 为 8adf8e6e-67b2-4cf2-a259-e3dc5476c621 (非库应用程序),则可以正常工作。但只有当我在天蓝色广告(企业应用程序下的非图库应用程序)中设置“秘密令牌”时将其留空时,它才有效。

我已经尝试了各种各样的事情,添加 OnChallenge 告诉我,如果我设置“秘密令牌”,则会发送一个挑战,但除此之外,我没有取得进一步的进展。

这里处理多个租户和秘密令牌的任何示例代码都会很棒

更新: 使用 options.TokenValidationParameters.IssuerValidator 我可以验证颁发者,从而使其与多个租户一起使用。我现在真正无法克服的是当我在此处输入“秘密令牌”时拨打电话:(见图)在此输入图像描述

Har*_*ngh 0

您可以访问Azure 门户中的管理企业应用程序的用户帐户配置,了解有关设置的更多信息:

在此输入图像描述