【问题标题】:IdentityServer3 - ScopeSecretValidator when using reference tokenIdentityServer3 - 使用参考令牌时的 ScopeSecretValidator
【发布时间】:2017-01-01 23:25:39
【问题描述】:

在收到访问令牌(引用访问令牌)后,我的 api 中间件调用自检端点以获取 jwt 令牌。不幸的是,我收到一个带有错误消息 unauthortize 的 json 响应。

2016-08-24 13:33:39.505 -04:00 [调试] 开始范围验证 2016-08-24 13:33:39.505 -04:00 [调试] 开始解析基本身份验证密码 2016-08-24 13:33:39.505 -04:00 [调试] 解析器发现秘密:“BasicAuthenticationSecretParser” 2016-08-24 13:33:39.505 -04:00 [信息] 发现秘密 ID:“webapp123.hybric.flow” 2016-08-24 13:33:39.507 -04:00 [信息] 找不到具有该名称的范围。中止 2016-08-24 13:33:39.507 -04:00 [警告] 范围未经授权调用自省端点。中止。

看起来我们正在使用传递给自检端点的客户端应用程序 ID 搜索客户端应用程序请求的范围。 问题:

他说的对吗? Id3 能记住客户请求的范围吗? 我可以使用 api ClientId 调用自省 endpint 吗? - 我不想使用请求引用令牌的客户端应用程序的客户端 ID。

代码如下:

var scope = (await _scopes.FindScopesAsync(new[] { parsedSecret.Id })).FirstOrDefault();

【问题讨论】:

    标签: identityserver3


    【解决方案1】:

    内省端点用于验证令牌而不是获取 Jwt。要调用 Introspection 端点,您需要在身份验证请求中传递“Scope”和“Scope secret”,而不是客户端 ID。 如果您将引用令牌发送到具有有效范围名称和秘密的自省端点,您将在响应中获得声明。

     public async Task ValidateValidReferenceTokenUsingIntrospectionEndPoint()
                {
                    var tokenResponse = await GetTokenResponseForClientCredentialsFlow(IdsModel.AccessTokenType.Reference);
    
                    var introspectionClient = new IntrospectionClient(
                       IntrospectionEndpoint,
                       "Api1",  // scope name, scope secret
                       "Api1Secret");
    
                    var response = await introspectionClient.SendAsync(new IntrospectionRequest
                    {
                        Token = tokenResponse.AccessToken
                    });
    
                    var jsonResult = JsonConvert.DeserializeObject<Dictionary<string, object>>(response.Raw);
    
                    response.IsActive.Should().Be(true);
                    response.IsError.Should().Be(false);
    
    
                    jsonResult.Should().Contain("iss", ValidIssuer);
                    jsonResult.Should().Contain("aud", ValidAudience);
                    jsonResult.Should().Contain("client_id", "referenceTokenClient");
    jsonResult.Should().Contain("client_claim1", "claim1value");
                    jsonResult.Should().Contain("active", true);
                }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-11-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-05
      相关资源
      最近更新 更多