大佬教程收集整理的这篇文章主要介绍了无法限制多租户应用程序中的身份验证颁发者(Blazor Server App/OpenIDConnect/Azure App Services),大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试向部署在 Azure 应用服务中的 Blazor 服务器应用添加多租户身份验证和授权。场景非常基础:
但第 2 步失败了。当我在 Azure 中部署我的应用程序时,我仍然可以使用来自未经验证的颁发者的帐户打开应用程序。这是我的代码(startup.cs):
public IConfiguration Configuration { get; }
public voID Configureservices(IserviceCollection services)
{
services.AddAuthentication(OpenIDConnectDefaults.AuthenticationscheR_260_11845@E)
.AddMicrosoftIDentityWebApp(options =>
{
Configuration.bind("AzureAd",options);
// ReStrict users to specific belonging to specific tenants
options.TokenValIDationParameters = new TokenValIDationParameters
{ ValIDateIssuer = true,// TrIEd first this,but with no effect:
// Validissuers = new List<String> {
// "https://sts.windows.net/<tenant1>/",// "https://sts.windows.net/<tenant2>/"
//},//So instead trIEd to use IssuerValIDator,but this dID not reStrict access either:
IssuerValIDator = ValIDateSpecificIssuers
};
});
services.AddControllersWithVIEws()
.AddMicrosoftIDentityUI();
//...
private String[] GetAcceptedTenantIDs()
{
return new[]
{
"<tenant1>","<tenant2>",};
}
public String ValIDateSpecificIssuers(String issuer,SecurityToken securityToken,TokenValIDationParameters valIDationParameters)
{
var validissuers = GetAcceptedTenantIDs().SELEct(tID => "https://login.microsoftonline.com/{tID}");
if (validissuers.Contains(issuer))
{
return issuer;
}
else
{
throw new SecurityTokenInvalidissuerException("The sign-in user's account does not belong to one of the tenants that this Web App accepts users from.");
}
}
我正在使用具有多组织身份验证的 Visual studio Blazor Server App 项目模板。相关代码部分没有其他更改(appsetTings.Json 中的“TenantID”:“Organizations”除外)。 我发现了这个 post,它说 Validissuer(s) 的行为不像人们预期的那样。这就是我尝试使用 IssuerValIDator 的原因。不幸的是,结果相同。
我错过了什么?接下来我应该尝试什么?
我终于弄明白了(感谢@JimXu,他说@R_723_10675@用 fiddler)。 问题出在我的Azure 应用服务和应用注册设置中:
ValidIssuers 不足以限制用户,所以我必须在那里安装 IssuerValidator。代码现在看起来像这样:
...
public void Configureservices(IserviceCollection services)
{
services.AddAuthentication(OpenIdConnectDefaults.AuthenticationscheR_260_11845@E)
.AddMicrosoftIdentityWebApp(options =>
{
Configuration.bind("AzureAd",options);
options.TokenValidationParameters = new TokenValidationParameters
{ ValidateIssuer = true,IssuerValidator = ValidateSpecificIssuers
};
});
...
private String[] GetAcceptedIssuers()
{
return new[]
{
"https://login.microsoftonline.com/<tenant1>/v2.0","https://login.microsoftonline.com/<tenant2>/v2.0",};
}
public String ValidateSpecificIssuers(String issuer,SecurityToken securityToken,TokenValidationParameters validationParameters)
{
var validIssuers = GetAcceptedIssuers();
if (validIssuers.Contains(issuer))
{
return issuer;
}
else
{
throw new SecurityTokenInvalidIssuerException("The sign-in user's account does not belong to one of the tenants that this Web App accepts users from.");
}
}
以上是大佬教程为你收集整理的无法限制多租户应用程序中的身份验证颁发者(Blazor Server App/OpenIDConnect/Azure App Services)全部内容,希望文章能够帮你解决无法限制多租户应用程序中的身份验证颁发者(Blazor Server App/OpenIDConnect/Azure App Services)所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。