【发布时间】:2017-01-25 13:03:38
【问题描述】:
我有一个包含 2 个区域的 WebAPI - 用户和管理员。 2 个站点,用户和管理员,使用它,他们有自己的客户端 ID。
public static readonly Scope AdminScope = new Scope
{
Name = "adm_api",
Type = ScopeType.Resource,
Claims = new List<ScopeClaim>
{
new ScopeClaim(Constants.ClaimTypes.Role),
new ScopeClaim(VitClaimTypes.IsAdmin)
},
};
public static readonly Scope UserScope = new Scope
{
Name = "user_api",
Type = ScopeType.Resource,
Claims = new List<ScopeClaim>
{
new ScopeClaim(Constants.ClaimTypes.Role),
new ScopeClaim(Constants.ClaimTypes.Name),
}
};
客户:
new Client
{
ClientName = "User area client",
ClientId = "user_client",
Enabled = true,
AllowedScopes = new List<string>
{
"user_api", "offline_access"
}
},
new Client
{
ClientName = "Admin area client",
ClientId = "adm_client",
Enabled = true,
AllowedScopes = new List<string>
{
"user_api", "adm_api"
}
},
现在我想拒绝请求“adm_api”范围但没有 IsAdmin 声明的用户登录。我怎么做?我知道我可以向 API 添加自定义 Authorize 属性,我会这样做。但与等待第一次 API 访问相比,在登录时立即拒绝访问会更加用户友好。
【问题讨论】:
标签: asp.net-web-api identityserver3 oauth2