【问题标题】:IdentityServer3 No scopeclaims when using reference tokenIdentityServer3 使用参考令牌时没有范围声明
【发布时间】: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


    【解决方案1】:

    参考令牌不像 JWT 那样是自包含令牌。它们提供了一个 ID,可用于从后备存储中获取引用令牌所代表的信息。

    如果您使用开箱即用的 IdentityServer3,您应该能够从 POST /connect/token 端点请求您的参考令牌,然后向令牌自省端点发出请求:

    POST /connect/accesstokenvalidation 令牌={tokenReceivedFromPreviousRequest}

    这将返回保存在其后备存储中的该引用令牌的信息,包括范围。

    请注意,该自省端点接受引用令牌和 JWT。

    【讨论】:

    猜你喜欢
    • 2017-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-18
    • 1970-01-01
    • 2015-10-03
    • 2021-10-01
    相关资源
    最近更新 更多