我正在使用spring授权服务器,但无法获取令牌。这是我的代码和示例。请帮我知道正确的请求
@Bean
public RegisteredClientRepository registeredClientRepository() {
RegisteredClient registeredClient = RegisteredClient.withId(UUID.randomUUID().toString())
.clientId("client")
.clientSecret("secret")
.clientAuthenticationMethod(ClientAuthenticationMethod.CLIENT_SECRET_BASIC)
.clientAuthenticationMethod(ClientAuthenticationMethod.CLIENT_SECRET_JWT)
.clientAuthenticationMethod(ClientAuthenticationMethod.CLIENT_SECRET_POST)
.clientAuthenticationMethod(ClientAuthenticationMethod.PRIVATE_KEY_JWT)
.authorizationGrantType(AuthorizationGrantType.PASSWORD)
.authorizationGrantType(AuthorizationGrantType.REFRESH_TOKEN)
.authorizationGrantType(AuthorizationGrantType.CLIENT_CREDENTIALS)
.authorizationGrantType(AuthorizationGrantType.JWT_BEARER)
.clientSettings(clientSettings -> clientSettings.requireUserConsent(true))
.build();
return new InMemoryRegisteredClientRepository(registeredClient);
}
这是我对基本身份验证客户端/秘密的请求
curl--位置--请求POST'http://localhost:9000/oauth2/token'
--header'授权:基本Y2xpZW50OnNlY3JldA=='
--header'内容类型:应用程序/x-wwww-form-urlencoded'
--header'Cookie:JSESSIONID=557C0348994EFC10DB8E7F06C2FDFF21'
--数据urlencode'grant_Type=client_credentials'
响应401:
{"错误":"invalid_client";}
您可以尝试将spring-security-oauth2-authorization-server
升级到更新的版本0.2.0
我在client_secret_post
上遇到了同样的问题,但后来升级版本对我来说很有效。
您正在使用的工件的groupId是什么?0.1.2
似乎是groupId = org.springframework.security.experimental
的最新版本
如果您将groupId更改为org.springframework.security
,您将看到0.2.2
和更高版本的