我有一个Oauth服务器。我为客户端使用InMemoryClientDetailsServiceBuilder。但即使我有很多授权类型,我的oauth客户端和服务器也总是使用authorization_code宏类型。为什么呢?
代码示例:
@Configuration
@EnableAuthorizationServer
public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter {
@Autowired
private AuthenticationManager authenticationManager;
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
endpoints.authenticationManager(authenticationManager);
}
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
clients.inMemory()
.withClient("myClient1")
.secret("dsfsdfewrewr324")
.authorizedGrantTypes("authorization_code", "refresh_token", "password")
.authorities("USER", "ADMIN")
.scopes("read", "write")
.autoApprove(true);
}
}
答案 0 :(得分:0)
我找到了答案。它取决于客户端授予类型属性。
我们可以在像这样的应用程序道具中配置它
my.client.clientId: myClient1
my.client.clientSecret: dsfsdfewrewr324
my.client.accessTokenUri: http://localhost:8789/server/oauth/access_token
my.client.userAuthorizationUri: http://localhost:8789/server/oauth/authorize
my.client.grantType=implicit
my.resource.userInfoUri: http://localhost:8789/server/api/me
但我们可以将grantType属性保留为空,因为某些OAuth2ProtectedResourceDetails实现(如AuthorizationCodeResourceDetails)会填充它。
我总是遇到错误,因为我总是使用AuthorizationCodeResourceDetails而不是ImplicitResourceDetails。
@Bean
@ConfigurationProperties("my.client")
public OAuth2ProtectedResourceDetails client() {
return new AuthorizationCodeResourceDetails();
}