代码之家  ›  专栏  ›  技术社区  ›  bielu000

为什么验证令牌成功后身份验证失败?

  •  0
  • bielu000  · 技术社区  · 6 年前

    我已经基于openidconnect概念创建了非常简单的identityserver。 身份验证后,我的身份服务器返回到我的应用程序jwttoken。 当我试图访问授权路由时,我有以下日志:

    Microsoft.aspnetcore.authentication.jwtbearer.jwtbearherhandler[2]

    已成功验证令牌。

    但在下面我有:

    Microsoft.aspnetcore.authentication.openidconnect.openidconnecthandler[7] OpenIDConnect未通过身份验证。失败消息:未验证

    我被重定向到我的identityserver中的auth route。

    为什么?

    以下是我的客户端(不是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;
            });
    
    1 回复  |  直到 6 年前
        1
  •  1
  •   j-hurst    6 年前

    如果您只需要使用identityserver对不承载令牌进行身份验证,请查看使用identityserver4.accesstokenvalidation nuget包。

    你的创业公司看起来像这样:

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