2017-05-09 53 views
0

我有一個使用Feign客戶端的spring啓動項目,並通過OAuth和JSON Web令牌處理授權。授權後,您必須通過GET參數發送訪問令牌。但不是將它作爲GET參數發送,我想在標題內發送它。我找不到一個辦法。任何人都知道嗎?Spring Boot:在標題中發送JWT(OAuth)

我的配置:

@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; 
    } 
} 

我已經GOOGLE了,但我發現這個東西是一種自我設計的,看起來相當複雜。

回答

0
  1. 作爲授權服務,客戶端必須通過調用/oauth/token的GET/POST API來生成令牌。在clientId,clientSecret,用戶名和密碼旁邊,您必須標識grant_type。無論如何,這個調用生成一個訪問令牌作爲JWT令牌。
  2. 客戶端獲取jwt令牌,從中提取訪問令牌並將其發送到資源服務器(以下是您的問題)授權承載頭。同樣的事情也該Authorization Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX25hbWUiOiJhZG1pbiIsInNjb3BlIjpbInJlYWQiLCJ3cml0ZSJdLCJleHAiOjE0OTUxMjE0NzYsImF1dGhvcml0aWVzIjpbIlJPTEVfQURNSU4iLCJST0xFX1VTRVIiXSwianRpIjoiNGYyNzQxMmMtNzkyOC00MWE5LTliMjQtN2I4ZmNmMTdiOGRhIiwidGVuYW50IjoidDEiLCJjbGllbnRfaWQiOiJjbGllbnQxIn0.Hwo7T8cAEFVm2NvXQUURiV2uiVz0nHz6RtXbOrFzGaK09TnTJJQmY8VKXsOble7prkveWBqLpWJk9J-9PRCntPW2Tsh5bjQJoFkkfHvT0Vc0TFarbFOh7St567rv5w0mYBNCxD28CM6dv_FHiz5wIoeEUeqQFIqojE3qo-aoT0o1ts-mO-Qmz-Dtla4-wGAYVgs84gQQ_n-U0kZzk_F09iHMgZRAIWq1ot2O6EZ8HHzaHA1gTsq5iWOZyxZAkGO0MTRyZir6vf8PoCHMn2Ge1uePl2NS0-UI5E8ozs2EXyGRHY6p-ZQTGvrUIObf_ZBQGgd37EoDBkrPK65kVqpZfw
  3. 資源服務器必須驗證JWT訪問令牌,如果資源服務器與授權服務器捆綁的資源服務器的配置取決於,所以他們都在同一個Spring上下文存在。
相關問題