Created
April 4, 2018 07:32
-
-
Save arony/8235b591e53eb55d5d2c5694edb9ecef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.nova.stats.relay; | |
import feign.RequestInterceptor; | |
import org.springframework.boot.autoconfigure.security.oauth2.resource.UserInfoRestTemplateFactory; | |
import org.springframework.cloud.client.loadbalancer.LoadBalanced; | |
import org.springframework.context.annotation.Bean; | |
import org.springframework.context.annotation.Configuration; | |
import org.springframework.http.HttpHeaders; | |
import org.springframework.security.oauth2.client.OAuth2ClientContext; | |
import org.springframework.security.oauth2.client.OAuth2RestTemplate; | |
import org.springframework.web.client.RestTemplate; | |
@Configuration | |
public class TokenRelayAutoConfiguration { | |
@Configuration | |
public static class RestTemplateConfiguration { | |
@Bean | |
@LoadBalanced | |
RestTemplate restTemplate() { | |
return new RestTemplate(); | |
} | |
} | |
@Configuration | |
public static class SecureRestTemplateConfiguration { | |
@Bean | |
@LoadBalanced | |
OAuth2RestTemplate restTemplate(UserInfoRestTemplateFactory factory) { | |
return factory.getUserInfoRestTemplate(); | |
} | |
} | |
@Configuration | |
public static class FeignAutoConfiguration { | |
@Bean | |
RequestInterceptor requestInterceptor(OAuth2ClientContext clientContext) { | |
return requestTemplate -> | |
requestTemplate.header(HttpHeaders.AUTHORIZATION, | |
clientContext.getAccessToken().getTokenType() + | |
' ' + clientContext.getAccessToken().getValue()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment