【问题标题】:Why authentication is failed after successfulyy validate token?为什么在成功验证令牌后身份验证失败?
【发布时间】:2018-07-20 01:42:34
【问题描述】:

我基于 OpenIdConnect 概念创建了非常简单的 IdentityServer。 身份验证后我的身份服务器返回到我的应用程序 JwtToken。 当我尝试访问授权路线时,我有以下日志:

Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler[2]

成功验证令牌。

但下面我有:

Microsoft.AspNetCore.Authentication.OpenIdConnect.OpenIdConnectHandler[7] OpenIdConnect 未通过身份验证。失败消息:未通过身份验证

我被重定向到身份服务器中的身份验证路由。

为什么会这样?

这是我的客户端(不是 IdentityServer)配置:

    services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
        .AddJwtBearer(options =>
        {
            options.IncludeErrorDetails = true;
            options.RequireHttpsMetadata = false;
            options.Audience = "http://localhost:5001";
            options.MetadataAddress = "http://localhost:5000/.well-known/openid-configuration";
            options.TokenValidationParameters = new TokenValidationParameters
            {
                ValidIssuer = "http://localhost:5000"
            };
        })
        .AddOpenIdConnect(options =>
        {
            options.SignInScheme = JwtBearerDefaults.AuthenticationScheme;
            options.AuthenticationMethod = OpenIdConnectRedirectBehavior.FormPost;
            options.MetadataAddress = "http://localhost:5000/.well-known/openid-configuration";
            options.RequireHttpsMetadata = false;
            options.ClientId = "user";
            options.ClientSecret = "secret";
            options.ResponseType = OpenIdConnectResponseType.CodeIdToken;
            options.SaveTokens = true;
        });

【问题讨论】:

    标签: c# asp.net-core openid-connect


    【解决方案1】:

    如果您只需要使用 IdentityServer 对不记名令牌进行身份验证,请查看使用 IdentityServer4.AccessTokenValidation nuget 包。

    你的创业公司应该是这样的:

    services.AddAuthentication(IdentityServerAuthenticationDefaults.AuthenticationScheme)
        .AddIdentityServerAuthentication(options =>
        {
          options.Authority = "IdentityServerURL";
          options.ApiName = "apiScope";
        });
    

    【讨论】:

      猜你喜欢
      • 2018-07-23
      • 1970-01-01
      • 2016-09-27
      • 2022-08-16
      • 1970-01-01
      • 1970-01-01
      • 2015-04-24
      • 2021-09-06
      • 1970-01-01
      相关资源
      最近更新 更多