Advertisement
SimpleCookie

Untitled

Apr 29th, 2024
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. import org.springframework.context.annotation.Bean
  2. import org.springframework.context.annotation.Configuration
  3. import org.springframework.http.client.ClientHttpRequestInterceptor
  4. import org.springframework.web.client.RestTemplate
  5. import org.springframework.web.client.support.OAuth1SigningInterceptor
  6.  
  7. @Configuration
  8. class RestClientConfiguration {
  9.  
  10. private val consumerKey = "your-consumer-key"
  11. private val consumerSecret = "your-consumer-secret"
  12.  
  13. @Bean
  14. fun restClient(): RestClient {
  15. val restClient = RestClient.builder()
  16. .restTemplate(oAuth1RestTemplate())
  17. .build()
  18. return restClient
  19. }
  20.  
  21. @Bean
  22. fun oAuth1RestTemplate(): RestTemplate {
  23. val restTemplate = RestTemplate()
  24. restTemplate.interceptors.add(oAuth1Interceptor())
  25. return restTemplate
  26. }
  27.  
  28. @Bean
  29. fun oAuth1Interceptor(): ClientHttpRequestInterceptor {
  30. return OAuth1SigningInterceptor(consumerKey, consumerSecret)
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement