【问题标题】:"Unexpected code_verifier" when trying to achieve authorization in hybrid flow (with PKCE) using IdentityServer4尝试使用 IdentityServer4 在混合流(使用 PKCE)中实现授权时出现“意外的 code_verifier”
【发布时间】:2017-07-30 19:28:30
【问题描述】:

我正在尝试实现本机客户端(最初将 .NET 控制台应用程序作为模型)以使用 OpenID Connect 对 IdentityServer4 作为我的 STS 进行身份验证。我使用 IdentityModel.OidcClient2 作为我的客户端库。
我选择实现基于代码的身份验证流程。

我能够通过身份验证阶段,但是当我进入授权阶段时,我在客户端收到一条错误消息,说

invalid_grant

在 IdentityServer 的错误消息是

“意外的 code_verifier:XXXXXXXXXXX....”


即使当我打开 fiddler 并查看请求和调试信息时 - 发送到 IdentityServer 以进行授权的代码验证器似乎是最初在 AuthorizationState 类中生成的客户端。
如果我使用AuthorizationState.CodeVerifier = null 执行,那么它可以工作。
但我确实想实施 PKCE 以获得额外的安全性。我怎样才能做到这一点?

这是特定客户端的配置
身份服务器:

            new Client
            {
                ClientId = "nativeapp1",
                ClientName = "Native App Demo - 1",
                AllowedGrantTypes = GrantTypes.Hybrid,

                RequireConsent = true,

                ClientSecrets =
                {
                    new Secret("some-secret1".Sha256())
                },

                AllowedScopes = {
                    IdentityServerConstants.StandardScopes.OpenId,
                    IdentityServerConstants.StandardScopes.Profile,
                    IdentityServerConstants.StandardScopes.OfflineAccess,
                    "custom.name",
                    "api1"
                },

                RedirectUris = {"http://127.0.0.1:7890/"},
                //PostLogoutRedirectUris = {"" }
                AllowOfflineAccess = true
            }

和客户端配置

var options = new OidcClientOptions
        {
            Authority = _authority,
            ClientId = "nativeapp1",
            RedirectUri = redirectUri,
            Scope = "openid profile api1 custom.name offline_access",
            FilterClaims = true,
            LoadProfile = false,
            Flow = OidcClientOptions.AuthenticationFlow.Hybrid,
            ClientSecret = "some-secret1"
        };

【问题讨论】:

    标签: asp.net-core identityserver4 openid-connect pkce


    【解决方案1】:

    您需要在 IdentityServer 的客户端配置中将 RequirePkce 设置为 true。

    【讨论】:

    • 按预期工作 :) 谢谢你,也感谢这个伟大的框架!
    猜你喜欢
    • 2020-08-17
    • 2020-12-08
    • 2021-08-03
    • 1970-01-01
    • 2021-10-15
    • 2021-03-18
    • 1970-01-01
    • 2019-10-30
    • 2011-05-08
    相关资源
    最近更新 更多