Invalid_client 在客户端应用程序中使用 OpenIdConnect
Invalid_client using OpenIdConnect in client application
我有一个 IdentityServer4 应用程序 运行 ASP.NET 身份。我想使用它,以便来自另一个应用程序的用户可以通过我的远程身份服务器登录。
我已使用以下设置在身份服务器中配置客户端应用程序(仅显示相关设置):
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: Message contains error:
'invalid_client', error_description: 'error_description is null',
error_uri: 'error_uri is null'.
对我来说,我使用的似乎是正确的 ClientId
?
我做错了什么?
ClientSecret 应包含未加密的值。看看 documentation.
你的情况秘密。
options.ClientSecret = "secret";
我没有进一步查看,所以如果此更改不能解决问题,请告诉我。
请检查客户端配置 (clientId),是否匹配给定的客户端配置。
就我而言,问题与秘密有关。
2 秘密问题注意事项:
- 在客户端应用程序中,'ClientSecret' 应该是 'unencryptedvalue' - 纯文本。(以下示例中的 'secret')
- 在为所有客户端进行配置时,在身份服务器中,请检查secret.Type,它应该是'SharedSecret'。
示例:
Secret secret = new Secret("secret".Sha256(), "Description");
secret.Type = "SharedSecret";
我有一个 IdentityServer4 应用程序 运行 ASP.NET 身份。我想使用它,以便来自另一个应用程序的用户可以通过我的远程身份服务器登录。
我已使用以下设置在身份服务器中配置客户端应用程序(仅显示相关设置):
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: Message contains error: 'invalid_client', error_description: 'error_description is null', error_uri: 'error_uri is null'.
对我来说,我使用的似乎是正确的 ClientId
?
我做错了什么?
ClientSecret 应包含未加密的值。看看 documentation.
你的情况秘密。
options.ClientSecret = "secret";
我没有进一步查看,所以如果此更改不能解决问题,请告诉我。
请检查客户端配置 (clientId),是否匹配给定的客户端配置。
就我而言,问题与秘密有关。
2 秘密问题注意事项:
- 在客户端应用程序中,'ClientSecret' 应该是 'unencryptedvalue' - 纯文本。(以下示例中的 'secret')
- 在为所有客户端进行配置时,在身份服务器中,请检查secret.Type,它应该是'SharedSecret'。
示例:
Secret secret = new Secret("secret".Sha256(), "Description");
secret.Type = "SharedSecret";