如果客户端中有几个指定的 grand 类型,将使用哪种授权类型?
Which grant type will be used, if there are a few specified grand types in the client?
我有一个 Oauth 服务器。我为客户使用 InMemoryClientDetailsServiceBuilder 。但是即使我有很多授权类型,我的 oauth 客户端和服务器也总是使用 authorization_code grand 类型。为什么?
代码示例:
@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);
}
}
我找到了答案。这取决于客户端授权类型 属性。
我们可以在application props中这样配置
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();
}
我有一个 Oauth 服务器。我为客户使用 InMemoryClientDetailsServiceBuilder 。但是即使我有很多授权类型,我的 oauth 客户端和服务器也总是使用 authorization_code grand 类型。为什么?
代码示例:
@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);
}
}
我找到了答案。这取决于客户端授权类型 属性。
我们可以在application props中这样配置
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();
}