【发布时间】:2020-10-12 18:25:09
【问题描述】:
我正在尝试为我们的 Saas 产品创建 Azure AD 配置(使用 scim2)。 我希望多个客户能够连接到他们的 Azure AD 租户。
微软在这里有参考代码:https://github.com/AzureAD/SCIMReferenceCode
但是,这设置为只允许一个租户,并且不使用您在 azure ad 中设置的“秘密令牌”。即使评论明确指出秘密令牌不应留空用于生产。
这是来自参考项目的重要代码
// 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
};
});
使用该代码,假设 Token:TokenIssuer 设置为 https://sts.windows.net/
我已经尝试了各种方法,添加 OnChallenge 告诉我如果我设置了“秘密令牌”就会发送一个挑战,但除此之外我没有进一步了解。
在这里处理多个租户和秘密令牌的任何示例代码都会很棒
更新: 使用 options.TokenValidationParameters.IssuerValidator 我可以验证颁发者,从而使其适用于多个租户。我现在真正无法超越的是,当我在这里输入“秘密令牌”时拨打电话:(见图)
【问题讨论】:
标签: c# asp.net-core azure-active-directory provisioning scim2