Я настраиваю сервер API REST, который должен работать только с потоком client_credentials, поэтому у меня нет пользователей, а есть только клиенты для доступа к моим ресурсам.
Я использую SPRING BOOT PARENT 2.0.2.RELEASE и Spring Security Oauth2 2.3.4.RELEASE
При попытке получить токен я получаю эту ошибку:
There is no client authentication. Try adding an appropriate authentication filter.
Вот как я настраиваю свой AuthServer
@Configuration
@EnableAuthorizationServer
public class AuthServer extends AuthorizationServerConfigurerAdapter {
@Autowired
@Qualifier("authenticationManagerBean")
private AuthenticationManager authenticationManager;
@Autowired
ClientDetailsService clientDetailsService;
@Override
public void configure(
AuthorizationServerSecurityConfigurer oauthServer)
throws Exception {
oauthServer
.allowFormAuthenticationForClients()
.tokenKeyAccess("permitAll()")
.checkTokenAccess("isAuthenticated()");
}
@Override
public void configure(ClientDetailsServiceConfigurer clients)
throws Exception {
clients.inMemory()
.withClient("client")
.secret("{noop}secret")
.authorizedGrantTypes("refresh_token", "client_credentials")
.scopes("read", "write");
}
@Override
public void configure(
AuthorizationServerEndpointsConfigurer endpoints)
throws Exception {
endpoints
.tokenStore(tokenStore())
.authenticationManager(authenticationManager)
.setClientDetailsService(clientDetailsService)
}
@Bean
public TokenStore tokenStore() {
return new InMemoryTokenStore();
}
}
Вот так я устанавливаю общий Security
@Configuration
@EnableWebSecurity
@Order(-1)
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/oauth/token").permitAll()
.and()
.csrf().disable()
.httpBasic().disable();
}
@Bean
@Override
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();
}
}
и, наконец, ResourceServer (что не должно быть важно в этом вопросе)
@Configuration
@EnableResourceServer
public class ResourceServerConf extends ResourceServerConfigurerAdapter{
@Override
public void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/api*")
.authenticated();
}
}
Я пытаюсь получить токен свызов POST / oauth / token таким образом oauth/token?client_id=client&client_secret=secret&grant_type=client_credentials
Что мне не хватает?