Getting invalid token using spring boot autoconfigure for the resource server #1355
Description
Hi,
I am trying to secure my Rest APIs.
I have created an auth server which is a spring boot project running separately.
I have put the auth server as below.
public class AuthServerOAuth2Config extends AuthorizationServerConfigurerAdapter {
private static final Logger log = LoggerFactory.getLogger(AuthServerOAuth2Config.class);
@Autowired
private AuthenticationManager authenticationManager;
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
clients
.inMemory()
.withClient("test")
.secret("testsecret")
.authorizedGrantTypes("client_credentials")
.scopes("write", "read");
}
@Override
public void configure(AuthorizationServerSecurityConfigurer security) throws Exception {
/*
* Allow our tokens to be delivered from our token access point as well as for tokens
* to be validated from this point
*/
security.checkTokenAccess("permitAll()");
}
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
endpoints.tokenStore(new InMemoryTokenStore()).authenticationManager(authenticationManager);
}
}
So auth server code is working and I am able to access a token by using the below end point url.
http://localhost:9092/uaa/oauth/token
I am able to validate the token / get the client info by using the below end point url.
http://localhost:9092/uaa/oauth/check_token?token=08ed1c9c-a371-43cc-b456-407fcde0b315
I have created a resource server which is a spring boot project running separately which has few Rest APIs accessible by end point URLs that needs to be secured. Below are the properties in the application.properties.
security.oauth2.resource.token-info-uri=http://localhost:9092/uaa/oauth/check_token
security.oauth2.resource.token-type=Bearer
security.oauth2.client.client-id=test
security.oauth2.client.client-secret=testsecret
security.oauth2.client.grant-type=client_credentials
security.oauth2.client.scope=write
I would assume that by mentioning the above properties, spring boot will first validate the token against the auth server by calling the token-info-uri mentioned above.
Now I am testing with POSTMAN by passing the "Bearer " as Authorization header to the one of the APIs in the resource server. I am getting the below error.
{
"error": "invalid_token",
"error_description": "08ed1c9c-a371-43cc-b456-407fcde0b315"
}
Though I can validate this token using the individual end point url "oauth/check_token", I am not able to validate this by accessing the APIs in the resource server.
Please help.
Thanks,
Sai