Java 如何在Spring OAuth2中仅通过客户端id和机密进行授权?
现在我使用下一个配置:Java 如何在Spring OAuth2中仅通过客户端id和机密进行授权?,java,spring-boot,spring-oauth2,Java,Spring Boot,Spring Oauth2,现在我使用下一个配置: @Configuration @EnableAuthorizationServer @EnableGlobalMethodSecurity(prePostEnabled = true) public class OAuth2Config extends AuthorizationServerConfigurerAdapter { @Override public void configure(ClientDetailsServiceConfigurer
@Configuration
@EnableAuthorizationServer
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class OAuth2Config extends AuthorizationServerConfigurerAdapter {
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
clients.jdbc(mAppConfig.dataSource())
.withClient("virto")
.secret("secret")
.authorizedGrantTypes("password", "authorization_code", "refresh_token");
}
}
它需要发送
客户端id、客户端密码、用户名、密码
。。。但是我需要为我的受信任服务器提供访问\u令牌
,这些服务器只有客户端id
和客户端机密
。。。我怎样才能做到?有可能吗?您需要的是配置一个具有客户端凭据授权的客户端
@Configuration
@EnableAuthorizationServer
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class OAuth2Config extends AuthorizationServerConfigurerAdapter {
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
clients.jdbc(mAppConfig.dataSource())
.withClient("virto")
.secret("secret")
.authorizedGrantTypes("client_credentials");
}
}
要获取令牌,您需要发送一个post请求,其中凭据为base 64编码
POST http://localhost:8080/paymentiq/oauth/token?grant_type=client_credentials -h 'Authorization: [clientId:secret]'
OAuth2中有一些流,例如
密码流
(需要客户端id、客户端密码、用户名和密码),客户端凭据
流,只需要客户端id和客户端密码
。您需要研究如何在SpringOAuth应用程序中启用client\u凭证
flow。有关更多信息,请参阅此SO帖子。