我目前正在关注本教程,了解如何使用微服务实现 oauth2 身份验证和授权:
http://stytex.de/blog/2016/02/01/spring-cloud-security-with-oauth2/
我让它按原样工作,但我很难弄清楚如何使用 HS256 而不是当前正在使用的 RSA256 算法来实现 jwt。
我想我已经将其范围缩小到 Oauth2Configuration 类中身份验证服务器的这段代码:
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
endpoints.tokenStore(tokenStore()).tokenEnhancer(jwtTokenEnhancer()).authenticationManager(authenticationManager);
}
@Autowired
@Qualifier("authenticationManagerBean")
private AuthenticationManager authenticationManager;
@Bean
public TokenStore tokenStore() {
return new JwtTokenStore(jwtTokenEnhancer());
}
@Bean
protected JwtAccessTokenConverter jwtTokenEnhancer() {
KeyStoreKeyFactory keyStoreKeyFactory = new KeyStoreKeyFactory(new ClassPathResource("jwt.jks"), "mySecretKey".toCharArray());
JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
converter.setKeyPair(keyStoreKeyFactory.getKeyPair("jwt"));
return converter;
}
更具体地说,我相信我必须用 jwtTokenEnhancer 方法改变一些东西。
我查看了文档,但没有看到任何与 HS256 相关的内容,因此将不胜感激任何形式的澄清。