I created multiple microservices with springboot 1.4. Last week I decided to implement oauth2 authorization service. My plan is something like,
Every request should be handled by zuul gateway which is registered by Eureka.
So the new Authorization service will be called by eureka to get access_token.
The problem I found is that I can able to get JWT access token directly from authorization server which is running in an another port(8081). when I tried to get the jwt token via zuul gateway, unfortunately I am getting an empty string.
Please take a look at my gateway configuration
application.yml (zuul-gateway)
zuul:
routes:
static:
path: /static/**
uaa:
path: /uaa/**
sensitive-headers:
serviceId: microservice-security-oauth2-server
users:
path: /users/**
serviceId: microservice-core-user
security:
basic:
enabled: false
application class of zuul is
@SpringBootApplication
@EnableZuulProxy
@EnableEurekaClient
@ComponentScan(basePackages={"com.configuration","com.zullfilter"})
public class ZullGatewayServerApplication {
public static void main(String[] args) {
SpringApplication.run(ZullGatewayServerApplication.class, args);
}
}
and the authorization server configuration class is
@Configuration
@EnableAuthorizationServer
public class OAuth2AuthorizationConfiguration extends AuthorizationServerConfigurerAdapter {
@Autowired
private AuthenticationManager authenticationManager;
@Autowired
private Environment environment;
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
endpoints.tokenStore(tokenStore())
.tokenEnhancer(jwtTokenEnhancer())
.authenticationManager(authenticationManager);
}
@Override
public void configure(AuthorizationServerSecurityConfigurer security) throws Exception {
security.tokenKeyAccess("permitAll()")
.checkTokenAccess("isAuthenticated()");
}
@Bean
public TokenStore tokenStore() {
return new JwtTokenStore(jwtTokenEnhancer());
}
@Bean
protected JwtAccessTokenConverter jwtTokenEnhancer() {
String pwd = environment.getProperty("keystore.password");
KeyStoreKeyFactory keyStoreKeyFactory = new KeyStoreKeyFactory(
new ClassPathResource("jwt.jks"),
pwd.toCharArray());
JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
converter.setKeyPair(keyStoreKeyFactory.getKeyPair("jwt"));
return converter;
}
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
clients.inMemory()
.withClient("service-account-1")
.secret("service-account-1-secret")
.authorizedGrantTypes("client_credentials")
.scopes("resource-server-read", "resource-server-write")
.accessTokenValiditySeconds(6000);
}
}
I am getting access_token requesting directly to
curl service-account-1:service-account-1-secret@localhost:8081/uaa/oauth/token -d grant_type=client_credentials
but when I am trying this with zuul proxy then I am getting an empty string
curl service-account-1:service-account-1-secret@localhost:8765/uaa/oauth/token -d grant_type=client_credentials
I am using zuul gateway version of 1.3 and spring boot 1.4
if anybody have faced this issue before please let me know