我正在运行 Spring Boot 授权服务器(版本 1.0.1)。当我在后端将客户端身份验证方法设置为 client_secret_post 并通过 Postman 发送以下请求时,我获得了访问令牌。
但是,当我将身份验证方法更改为 client_secret_basic 并通过 Postman 发送以下请求时,我收到了 invalid_client 错误。
我在这里附上 HTTP 请求和错误响应的控制台输出以供参考。
据我了解,当我们使用 client_secret_basic 作为客户端身份验证方法时,我们应该在 Authorization 标头中以 base64 编码格式发送 clientId 和 clientSecret。这种理解是正确的还是我遗漏了什么?
如果您的
invalid_client
没有RegisteredClient
作为允许的client_secret_basic
,您将收到clientAuthenticationMethod
错误。确保您都指定了。例如,当使用内存客户端时(出于演示目的):
@Bean
public RegisteredClientRepository registeredClientRepository() {
RegisteredClient registeredClient = RegisteredClient.withId(UUID.randomUUID().toString())
.clientId("messaging-client")
.clientSecret("{noop}secret")
// **** Ensure both are allowed if both methods are needed
.clientAuthenticationMethod(ClientAuthenticationMethod.CLIENT_SECRET_BASIC)
.clientAuthenticationMethod(ClientAuthenticationMethod.CLIENT_SECRET_POST)
// ****
.authorizationGrantType(AuthorizationGrantType.AUTHORIZATION_CODE)
.authorizationGrantType(AuthorizationGrantType.REFRESH_TOKEN)
.authorizationGrantType(AuthorizationGrantType.CLIENT_CREDENTIALS)
.authorizationGrantType(OAuth2DeviceCode.GRANT_TYPE)
.redirectUri("http://127.0.0.1:8080/login/oauth2/code/messaging-client-oidc")
.redirectUri("http://127.0.0.1:8080/authorized")
.scope(OidcScopes.OPENID)
.scope(OidcScopes.PROFILE)
.scope("message.read")
.scope("message.write")
.clientSettings(ClientSettings.builder().requireAuthorizationConsent(true).build())
.build();
return new InMemoryRegisteredClientRepository(registeredClient);
}
如果这不能解决您的问题,请分享您的配置。