carnellj / spmia-chapter7

Source code for chapter 7 of Spring Microservices in Action
46 stars 131 forks source link

JWT Example, Chapter 7, How do DefaultTokenServices defaultTokenServices work? #10

Open ChaosDeSelva opened 5 years ago

ChaosDeSelva commented 5 years ago

In file JWTOAuth2Config.java shouldn't the configure function also have endpoints.tokenServices(tokenServices) ? tokenServices is autowired in this file but never used? When I add it myself I lose the JWT token and start getting the original oauth uid token again.

` @Override public void configure(AuthorizationServerEndpointsConfigurer endpoints) { TokenEnhancerChain tokenEnhancerChain = new TokenEnhancerChain(); tokenEnhancerChain.setTokenEnhancers(Arrays.asList(jwtTokenEnhancer, jwtAccessTokenConverter));

    endpoints.tokenStore(tokenStore)
        .accessTokenConverter(jwtAccessTokenConverter)
        .tokenEnhancer(tokenEnhancerChain)
        .tokenServices(tokenServices) // I added this
        .authenticationManager(authenticationManager)
        .userDetailsService(userDetailsService);
}

`

I am confused how the DefaultTokenServices work because I added defaultTokenServices.setAccessTokenValiditySeconds(7200); and its not working. So I am confused how tokenServices even work in this setup?

`
@Bean @Primary public DefaultTokenServices tokenServices() { DefaultTokenServices defaultTokenServices = new DefaultTokenServices();

    defaultTokenServices.setTokenStore(tokenStore());
    defaultTokenServices.setAccessTokenValiditySeconds(7200);  // I added this
    defaultTokenServices.setSupportRefreshToken(true);
    return defaultTokenServices;
}

`