【发布时间】:2020-06-17 06:48:06
【问题描述】:
我有一个身份服务器设置,具有以下“看起来像”配置:
return new List<Client>
{
new Client
{
[...]
AllowedGrantTypes = GrantTypes.Implicit,
[....]
},
new Client
{
[...]
AllowedGrantTypes = GrantTypes.ClientCredentials,
[....]
}
};
和这样注释的控件:
[Route("api/forms")]
[ApiController]
[Authorize(Policy = "user.api.portfolio.manager")]
[Authorize(Policy = "application.api.portfolio.manager")]
public class FormsController : ControllerBase
{
[...]
}
和政策
private System.Action<AuthorizationOptions> AddJwtAuthorizationPolicyForRole()
{
return options => { options.AddPolicy("**POLICY_FOR_GRANT_IMPLICIT**", policy => {
policy.AuthenticationSchemes.Add(JwtBearerDefaults.AuthenticationScheme);
policy.RequireAuthenticatedUser();
policy.RequireClaim(ClaimTypes.Role, "USER_ACCESSIBLE");
});
};
}
private System.Action<AuthorizationOptions> AddJwtAuthorizationPolicyForRole()
{
return options => { options.AddPolicy("**POLICY_FOR_CLIENT_CREDENTIALS**", policy => {
policy.AuthenticationSchemes.Add(JwtBearerDefaults.AuthenticationScheme);
policy.RequireAuthenticatedUser();
});
};
}
所以我想实现:
使用 GrantType.ClientCredentials 的客户端无需任何进一步的需求即可访问控制器。 使用隐式模式的客户端必须具有角色 USER_ACCESSIBLE
如果配置如上所示,则必须应用两种策略 -> 两种授权类型均失败。
如何使用 IdentityServer 实现所描述的行为,每个授权类型可能有一个独立的策略以便应用?
提前感谢您的帮助。
【问题讨论】:
标签: c# .net asp.net-core identityserver4 policies