【问题标题】:IdentityServer4 Signing Certificate Reference tokensIdentityServer4 签名证书参考令牌
【发布时间】:2018-10-02 19:16:39
【问题描述】:

当 api 尝试验证引用令牌时出现错误。我们的身份服务器将仅提供参考令牌。为什么需要签名证书。该错误与键集有关。

System.InvalidOperationException: Policy error while contacting the discovery endpoint https://****.net/.well-known/openid-configuration: Keyset is missing
   at IdentityModel.AspNetCore.OAuth2Introspection.PostConfigureOAuth2IntrospectionOptions.GetIntrospectionEndpointFromDiscoveryDocument(OAuth2IntrospectionOptions Options)
   at IdentityModel.AspNetCore.OAuth2Introspection.PostConfigureOAuth2IntrospectionOptions.InitializeIntrospectionClient(OAuth2IntrospectionOptions Options)
   at IdentityModel.AspNetCore.OAuth2Introspection.OAuth2IntrospectionHandler.LoadClaimsForToken(String token)
   at IdentityModel.AspNetCore.OAuth2Introspection.OAuth2IntrospectionHandler.HandleAuthenticateAsync()
   at Microsoft.AspNetCore.Authentication.AuthenticationHandler`1.AuthenticateAsync()
   at Microsoft.AspNetCore.Authentication.AuthenticationService.AuthenticateAsync(HttpContext context, String scheme)
   at IdentityServer4.AccessTokenValidation.IdentityServerAuthenticationHandler.HandleAuthenticateAsync()
   at Microsoft.AspNetCore.Authentication.AuthenticationHandler`1.AuthenticateAsync()
   at Microsoft.AspNetCore.Authentication.AuthenticationService.AuthenticateAsync(HttpContext context, String scheme)
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Cors.Infrastructure.CorsMiddleware.Invoke(HttpContext context)
   at Ips.Middleware.SerilogMiddleware.Invoke(HttpContext httpContext)
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)

【问题讨论】:

  • 您能否添加额外的详细信息,例如确切的错误消息或异常详细信息和堆栈跟踪?
  • 添加了额外信息

标签: asp.net-core identityserver4


【解决方案1】:

似乎有东西正在验证发现文档以确保其格式正确。您可能可以通过覆盖策略来禁用此验证,但由于无论如何您都需要 id_tokens 的签名密钥,因此您最好设置签名和验证凭据。

【讨论】:

  • 听起来我错过了什么。我的理解是引用令牌没有被烧掉?
  • 确实没有,但您使用的库仍在尝试验证发现文档。即使使用引用访问令牌, id_token 仍然是 JWT,除非我错了。
【解决方案2】:

您可以通过在 IdentityServer 中设置 IdentityServerOptions 来停止从 DiscoveryEndpoint 返回的关键信息:

options.Discovery.ShowKeySet = false;

看PostConfigureOAuth2IntrospectionOptions.InitializeIntrospectionClient的实现:

    private async Task<IntrospectionClient> InitializeIntrospectionClient(OAuth2IntrospectionOptions Options)
    {
        string endpoint;

        if (Options.IntrospectionEndpoint.IsPresent())
        {
            endpoint = Options.IntrospectionEndpoint;
        }
        else
        {
            endpoint = await GetIntrospectionEndpointFromDiscoveryDocument(Options).ConfigureAwait(false);
            Options.IntrospectionEndpoint = endpoint;
        }

        IntrospectionClient client;
        if (Options.IntrospectionHttpHandler != null)
        {
            client = new IntrospectionClient(
                endpoint,
                headerStyle: Options.BasicAuthenticationHeaderStyle,
                innerHttpMessageHandler: Options.IntrospectionHttpHandler);
        }
        else
        {
            client = new IntrospectionClient(endpoint);
        }

        client.Timeout = Options.DiscoveryTimeout;
        return client;
    }

您可以通过在OAuth2IntrospectionOptions 上设置IntrospectionEndpoint 属性来避免调用GetIntrospectionEndpointFromDiscoveryDocument

【讨论】:

  • 对于引用令牌需要进行自省。
  • 它不会关闭内省。它只会停止从发现中配置 IntrospectionEndpoint。无论如何,我的第一个建议 (options.Discovery.ShowKeySet = false) 应该可以正确解决您的问题
【解决方案3】:

找到了解决方案。您无需更改身份。更改是针对 api 的。

 services.AddAuthentication(IdentityServerAuthenticationDefaults.AuthenticationScheme)
    .AddIdentityServerAuthentication(
    IdentityServerAuthenticationDefaults.AuthenticationScheme, 
    //Null if you do not want to support jwt bearer tokens
    null,
    options =>
    {
      options.Authority = "https://yourIdentityServer.com";
      //This is the key
      options.DiscoveryPolicy.RequireKeySet = false;
      options.ClientId = "xxxx";
      options.ClientSecret = "xxxx";
    });

【讨论】:

    猜你喜欢
    • 2017-11-19
    • 1970-01-01
    • 1970-01-01
    • 2012-10-01
    • 2021-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多