OkHttpTokenInterceptor.java 731 B

123456789101112131415161718192021222324252627
  1. package com.yaozhitech.spring5.intercept;
  2. import org.springframework.beans.factory.annotation.Value;
  3. import org.springframework.context.annotation.Configuration;
  4. import com.yaozhitech.spring5.utils.JwtUtils;
  5. import feign.RequestInterceptor;
  6. import feign.RequestTemplate;
  7. @Configuration
  8. public class OkHttpTokenInterceptor implements RequestInterceptor{
  9. @Value("${spring.application.name}")
  10. private String applicationName;
  11. @Value("${auth.client.secret}")
  12. private String clientSecret;
  13. @Override
  14. public void apply(RequestTemplate template) {
  15. template.header("x-auth-client", JwtUtils.sign(applicationName + "." + clientSecret, JwtUtils.generateSalt(), 3600));
  16. template.header("x-auth-token", "gateway");
  17. }
  18. }