I try to implement custom Auth Server and Client. I use as example this code. I modified Tonr2 application to not to use any users. I want to convert this 2 application. Tonr2 should create session of user based on session from Sparklr2. Now I modified this parts:
In Sparklr2 (ResourceConfiguration class):
@Bean
public OAuth2ProtectedResourceDetails sparklr() {
ClientCredentialsResourceDetails details = new ClientCredentialsResourceDetails();
details.setId("sparklr/tonr");
details.setClientId("tonr");
details.setClientSecret("secret");
details.setAccessTokenUri(accessTokenUri);
details.setAuthenticationScheme(AuthenticationScheme.query);
details.setClientAuthenticationScheme(AuthenticationScheme.form);
details.setScope(Arrays.asList("read", "write"));
return details;
}
In Tonr2:
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
// I removed all users
// @Override
// protected void configure(AuthenticationManagerBuilder auth) throws Exception {
// auth.inMemoryAuthentication().withUser("marissa").password("wombat").roles("USER").and().withUser("sam")
// .password("kangaroo").roles("USER");
// }
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/resources/**");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/sparklr/**").permitAll();
}
}
And:
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
clients.inMemory().withClient("tonr")
.resourceIds(SPARKLR_RESOURCE_ID)
.authorizedGrantTypes("client_credentials")
//.authorities("ROLE_CLIENT")
.scopes("read", "write")
.secret("secret");
But I got:
RestTemplate - POST request for "http://localhost:8080/sparklr2/oauth/token" resulted in 401 (Unauthorized); invoking error handler
error="access_denied", error_description="Error requesting access token."
at org.springframework.security.oauth2.client.token.OAuth2AccessTokenSupport.retrieveToken(OAuth2AccessTokenSupport.java:145)
How to fix it? Or maybe you have some example how to do this properly?