【发布时间】:2017-02-15 07:11:38
【问题描述】:
在 IdentityServer 中,我添加了一个像这样的新范围:
new Scope
{
Name = "myscope",
Description = "myscope",
Type=ScopeType.Resource,
ShowInDiscoveryDocument= false,
Emphasize = false,
//AccessTokenType=1, //Reference
AccessTokenType=0, //JWT
Claims = new List<ScopeClaim>
{
new ScopeClaim("location"),
}
我添加了一个客户:
new Client
{
ClientName = "myclient",
Enabled = true,
ClientId = "myclient",
Flow = Flows.Implicit,
AllowedScopes = new List<string> {"myscope"},
Claims = new List<Claim> {new Claim("location", "datacenter")}
}
我添加了 GetProfileData 的实现:
public override async Task GetProfileDataAsync(ProfileDataRequestContext context)
{
await base.GetProfileDataAsync(context);
if (context.AllClaimsRequested)
context.IssuedClaims = context.Subject.Claims;
else if (context.RequestedClaimTypes != null)
context.IssuedClaims = context.Subject.Claims.Where(claim => context.RequestedClaimTypes.Contains(claim.Type)).ToList();
}
在我的 webapi 中,我使用的是 AccessTokenValidation:
app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions
{
Authority = "http://localhost:5300",
AllowedScopes = { "myscope" },
RequireHttpsMetadata = false,
});
services.AddAuthorization(options =>
{
options.AddPolicy("location", policy => policy.RequireClaim("location"));
});
我的控制器前缀为:
[Authorize(ActiveAuthenticationSchemes = "Bearer", Policy = "location")]
public async Task<IActionResult> Get()
{
...
}
现在,当 accesstoken 设置为 JWT 时,一切正常,我可以调用端点。现在,如果我将 AccessTokenType 更改为引用令牌,它会失败...... 如果我在调用 profiledata 端点期间检查 RequestedClaimTypes,它会在使用 JWT 时保存“myscope”的声明,但在使用引用令牌时不保存...... 我是否缺少一些配置或者这是它应该工作的方式?我本来希望在两种设置中都获得相同的声明
【问题讨论】:
标签: identityserver3