在客户端应用程序中使用OpenIdConnect的Invalid_client

时间:2019-11-18 21:43:30

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

我有一个使用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

client id

enter image description here

我的客户端应用程序(服务器端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_uri:“ error_uri为空”。

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

我在做什么错?

2 个答案:

答案 0 :(得分:4)

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

在您的情况下秘密

options.ClientSecret = "secret";

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

答案 1 :(得分:0)

此问题要注意的两件事:

  1. 在客户端应用程序中,“ ClientSecret”应为“ unencryptedvalue”-纯文本。(在下面的示例中为“ secret”)
  2. 在为所有客户端进行配置时,请在身份服务器中检查密码。类型应为“ SharedSecret”。

示例:

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