【发布时间】:2017-10-07 08:20:07
【问题描述】:
我有一个使用 Feign 客户端的 spring boot 项目,并通过 OAuth 和 JSON Web Tokens 处理授权。授权后,您必须通过 GET 参数发送访问令牌。但是,我不想将其作为 GET 参数发送,而是将其发送到标题中。我找不到办法。有人知道吗?
我的配置:
@Configuration
@EnableAuthorizationServer
public class AuthorizationServerConfiguration extends AuthorizationServerConfigurerAdapter {
@Autowired
@Qualifier("authenticationManagerBean")
private AuthenticationManager authenticationManager;
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
clients.inMemory()
.withClient(oAuth2ClientName)
.authorizedGrantTypes("password", "authorization_code", "refresh_token", "implicit")
.authorities("ROLE_CLIENT", "ROLE_TRUSTED_CLIENT")
.scopes("read", "write", "trust")
.secret(oAuth2ClientSecret)
.accessTokenValiditySeconds(oAuth2AccessTokenValidSecs).
refreshTokenValiditySeconds(oAuth2RefreshTokenValidSecs);
}
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
endpoints.tokenStore(tokenStore())
.accessTokenConverter(accessTokenConverter())
.authenticationManager(authenticationManager);
}
@Bean
public TokenStore tokenStore() {
return new JwtTokenStore(accessTokenConverter());
}
@Bean
public JwtAccessTokenConverter accessTokenConverter() {
JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
converter.setSigningKey(jwtSigningKey);
return converter;
}
@Bean
@Primary
public DefaultTokenServices tokenServices() {
DefaultTokenServices defaultTokenServices = new DefaultTokenServices();
defaultTokenServices.setTokenStore(tokenStore());
defaultTokenServices.setSupportRefreshToken(true);
return defaultTokenServices;
}
}
我已经用谷歌搜索过了,但我发现的东西是自行设计的,看起来很复杂。
【问题讨论】:
标签: spring spring-boot oauth jwt