代码流不适用于Identity Server 4

时间:2019-09-13 03:24:26

标签: identityserver4 openid-connect .net-core-3.0

我正在尝试更新.NET Core 3.0 React SPA,以使用代码流而不是隐式代码。

在Identity Server日志中出现“无效授权代码”失败。

谁能告诉我出了什么问题或要检查/尝试什么?

我需要为PKCE做任何事情吗?或只是将其设置为true? (RequirePkce = true)

似乎在出错之前采取了公平的方法。

我在前端使用oidc-client NPM软件包。

  

[13:14:44信息]调用IdentityServer端点:“ /。众所周知/ openid-配置”(IdentityServer4.Hosting.IdentityServerMiddleware)的“ IdentityServer4.Endpoints.DiscoveryEndpoint”

     

[13:14:44信息]调用IdentityServer端点:“ / connect / token”的“ IdentityServer4.Endpoints.TokenEndpoint”(IdentityServer4.Hosting.IdentityServerMiddleware)

     

[13:14:44信息] ClientAuthenticationSuccessEvent {ClientId:“ MyProject.web”,AuthenticationMethod:“ NoSecret”,类别:“ Authentication”,名称:“ Client Authentication Success”,EventType:Success,Id:1010,消息:null,ActivityId:“ 80000050-0007-fe00-b63f-84710c7967bb”,时间戳记:09/13/2019 03:14:44,ProcessId:19196,LocalIpAddress:“ :: 1:44343”,RemoteIpAddress:“ :: 1 “}(IdentityServer4.Events.DefaultEventService)

     

[13:14:44信息] 令牌请求验证成功   TokenRequestValidationLog {ClientId:“ MyProject.web”,ClientName:“ MyProject.web”,GrantType:“ authorization_code”,范围:null,AuthorizationCode:“ d473eae4ba0ca70d14ac02b1907466067ae97847cdba5f46ba78ce6a51d4c171”,RefreshTokenes:null,用户名:的IdP:空原材料:[( “CLIENT_ID”: “MyProject.web”),( “代码”: “d473eae4ba0ca70d14ac02b1907466067ae97847cdba5f46ba78ce6a51d4c171”),( “REDIRECT_URI”: “https://localhost:44343/authentication/login-callback”),( “code_verifier”:“7103488868084ec4aa94a62bcb9b422eac6fc24203eb4b14a8fdc9f3cad9839c358780cc40c546ecb8d58ac5e118b63e “),(” grant_type“:” authorization_code“)]}(IdentityServer4.Validation.TokenRequestValidator)

     

[13:14:44信息] TokenIssuedSuccessEvent {ClientId:“ MyProject.web”,ClientName:“ MyProject.web”,RedirectUri:null,端点:“ Token”,SubjectId:null,范围:“ openid配置文件MyProject.webAPI”,GrantType:“ authorization_code”,令牌:[令牌{令牌类型:“ id_token”,令牌值:“ **** gPHA”},令牌{令牌类型:“ access_token”,令牌值:“ * *** YH5A“}],类别:”令牌“,名称:”令牌已成功发行“,事件类型:成功,ID:2000,消息:空,ActivityId:” 80000050-0007-fe00-b63f-84710c7967bb“,时间戳: 09/13/2019 03:14:44,ProcessId:19196,LocalIpAddress:“ :: 1:44343”,RemoteIpAddress:“ :: 1”}(IdentityServer4.Events.DefaultEventService)

     

[13:14:44信息]调用IdentityServer端点:“ / connect / userinfo”的“ IdentityServer4.Endpoints.UserInfoEndpoint”(IdentityServer4.Hosting.IdentityServerMiddleware)

     

[13:14:44信息]个人档案服务返回了以下声明类型:“ given_name family_name”   (IdentityServer4.ResponseHandling.UserInfoResponseGenerator)

     

[13:14:44信息]调用IdentityServer端点:“ / connect / token”的“ IdentityServer4.Endpoints.TokenEndpoint”(IdentityServer4.Hosting.IdentityServerMiddleware)

     

[13:14:44信息] ClientAuthenticationSuccessEvent {ClientId:“ MyProject.web”,AuthenticationMethod:“ NoSecret”,类别:“ Authentication”,名称:“ Client Authentication Success”,EventType:成功,ID:1010,消息:null,ActivityId:“ 8000000c-0002-fc00-b63f-84710c7967bb”,时间戳:09/13/2019    03:14:44,ProcessId:19196,LocalIpAddress:“ :: 1:44343”,RemoteIpAddress:“ :: 1”}(IdentityServer4.Events.DefaultEventService)

     

[13:14:44错误]无效的授权代码{代码:“ d473eae4ba0ca70d14ac02b1907466067ae97847cdba5f46ba78ce6a51d4c171”},详细信息:TokenRequestValidationLog {ClientId:“ MyProject.web”,ClientName:“ MyProject.web” _ GrantCode:“作者” ,范围:null,AuthorizationCode:“ d473eae4ba0ca70d14ac02b1907466067ae97847cdba5f46ba78ce6a51d4c171”,RefreshToken:null,UserName:null,AuthenticationContextReferenceClasses:null,承租人:null,IdP:null,Raw:[(“ client_id”):“ MyProject。 :“”   (IdentityServer4.Validation.TokenRequestValidator)

     

[13:14:44信息] TokenIssuedFailureEvent {ClientId:“ MyProject.web”,ClientName:“ MyProject.web”,RedirectUri:null,端点:“ Token”,SubjectId:null,范围:null,GrantType:“授权代码”,错误:“ invalid_grant”,错误描述:null,类别:“ Token”,名称:“ Token Issued Failure”,EventType:Failure,Id:2001,消息:null,ActivityId:“ 8000000c-0002-fc00-b63f- 84710c7967bb”,时间戳:09/13/2019 03:14:44,ProcessId:19196,LocalIpAddress:“ :: 1:44343”,RemoteIpAddress:“ :: 1”}(IdentityServer4.Events.DefaultEventService)

1 个答案:

答案 0 :(得分:1)

以下是Identity Server 4的授权代码流的实现

public class Example
{
    public static IEnumerable<Test> Get()
    {
        var shakey = new Secret { Value = "mysecret".Sha512() };

        return new List<Test> {
            new Test {
                TestId = "authorizationCodeTest2",
                TestName = "Authorization Code Test",
                TestSecrets = new List<Secret> { shakey },
                Enabled = true,
                AllowedGrantTypes = new List<string> { "authorization_code" },
                AllowRememberConsent = false,
                RequireConsent = true,
                RedirectUris =
                  new List<string> {
                       "http://localhost:<<port>>/account/oAuth2"
                  },
                PostLogoutRedirectUris =
                  new List<string> {"http://localhost:<<port>>"},
                AllowedScopes = new List<string> {
                    "api"
                },
                AccessTokenType = AccessTokenType.Jwt
            }
        };
    }
}

检查是否在身份验证令牌上缺少某些内容,然后重试。