【问题标题】:Invalid_client using OpenIdConnect in client application在客户端应用程序中使用 OpenIdConnect 的 Invalid_client
【发布时间】:2022-03-10 17:31:28
【问题描述】:

我有一个使用 ASP.NET Identity 运行的 IdentityServer4 应用程序。我想使用它,以便来自另一个应用程序的用户可以通过我的远程身份服务器登录。

我在身份服务器中配置了一个客户端应用程序,具有以下设置(仅显示相关设置):

ClientId: mvc
ProtocolType: oidc
ClientSecret: K7gNU3sdo+OL0wNhqoVWhr3g6s1xYv72ol/pe/Unols=

(URLs to client app)
RedirectUri: https://localhost:44313/signin-oidc
PostLogoutRedirectUri: https://localhost:44313/signout-callback-oidc

GrantType: Hybrid

我的客户端应用程序(服务器端 Blazor 应用程序)在 Startup.cs 中配置了以下设置。

        // Add authentication
        services.AddAuthentication(options =>
        {
            options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
            options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
        })
        .AddCookie(CookieAuthenticationDefaults.AuthenticationScheme)
        .AddOpenIdConnect(OpenIdConnectDefaults.AuthenticationScheme, options =>
        {
            options.RequireHttpsMetadata = false;
            options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
            options.Authority = "http://localhost:5000/"; // local identity server url
            options.ClientId = "mvc";
            options.ClientSecret = "K7gNU3sdo+OL0wNhqoVWhr3g6s1xYv72ol/pe/Unols=";
            options.ResponseType = OpenIdConnectResponseType.CodeIdToken;
            options.SaveTokens = true;
            options.GetClaimsFromUserInfoEndpoint = true;
            options.Scope.Add("profile openid web_api");
        });

当我启动我的客户端应用程序时,我会重定向到我的 IdentityServer 登录页面。然后我可以使用用户名和密码登录。当我登录时,我会被重定向回我的客户端应用程序https://localhost:44313/signin-oidc

然后我在该页面上收到以下错误:

OpenIdConnectProtocolException:消息包含错误: 'invalid_client', error_description: 'error_description 为空', error_uri: 'error_uri 为空'。

在我看来,我使用的是正确的ClientId

我做错了什么?

【问题讨论】:

    标签: asp.net-identity openid identityserver4 openid-connect


    【解决方案1】:

    ClientSecret 应该包含未加密的值。看看documentation

    在你的情况下秘密

    options.ClientSecret = "secret";
    

    我没有进一步查看,所以如果此更改不能解决问题,请告诉我。

    【讨论】:

      【解决方案2】:

      请检查客户端配置(clientId),是否匹配给定的客户端配置。

      就我而言,问题与秘密有关。

      2 秘密问题的注意事项:

      1. 在客户端应用程序中,'ClientSecret' 应该是'unencryptedvalue' - 明文。(以下示例中的'secret')
      2. 在为所有客户端进行配置时,请在身份服务器中检查 secret.Type,它应该是“SharedSecret”。

      例子:

      Secret secret = new Secret("secret".Sha256(), "Description");
      secret.Type = "SharedSecret";
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-05-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-02-20
        • 2016-03-02
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多