我有一个使用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;
}
}
我已经用谷歌搜索了它,但我发现的东西有点自我设计,看起来很复杂。
答案 0 :(得分:0)
/oauth/token
的GET / POST api生成令牌。除了clientId,clientSecret,用户名和密码,您必须标识grant_type。无论如何,这个调用会生成一个访问令牌作为JWT令牌。Authorization Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX25hbWUiOiJhZG1pbiIsInNjb3BlIjpbInJlYWQiLCJ3cml0ZSJdLCJleHAiOjE0OTUxMjE0NzYsImF1dGhvcml0aWVzIjpbIlJPTEVfQURNSU4iLCJST0xFX1VTRVIiXSwianRpIjoiNGYyNzQxMmMtNzkyOC00MWE5LTliMjQtN2I4ZmNmMTdiOGRhIiwidGVuYW50IjoidDEiLCJjbGllbnRfaWQiOiJjbGllbnQxIn0.Hwo7T8cAEFVm2NvXQUURiV2uiVz0nHz6RtXbOrFzGaK09TnTJJQmY8VKXsOble7prkveWBqLpWJk9J-9PRCntPW2Tsh5bjQJoFkkfHvT0Vc0TFarbFOh7St567rv5w0mYBNCxD28CM6dv_FHiz5wIoeEUeqQFIqojE3qo-aoT0o1ts-mO-Qmz-Dtla4-wGAYVgs84gQQ_n-U0kZzk_F09iHMgZRAIWq1ot2O6EZ8HHzaHA1gTsq5iWOZyxZAkGO0MTRyZir6vf8PoCHMn2Ge1uePl2NS0-UI5E8ozs2EXyGRHY6p-ZQTGvrUIObf_ZBQGgd37EoDBkrPK65kVqpZfw
答案 1 :(得分:0)
如果您想使用最新的 Spring Boot 库,请参阅我对如何让 client_credentials 在 https://stackoverflow.com/a/65741386/698471 上工作的回复