use of com.okta.spring.boot.oauth.http.UserAgentRequestInterceptor in project okta-spring-boot by okta.
the class OktaOAuth2ResourceServerAutoConfig method restTemplate.
static RestTemplate restTemplate(OktaOAuth2Properties oktaOAuth2Properties) {
Proxy proxy;
OktaOAuth2Properties.Proxy proxyProperties = oktaOAuth2Properties.getProxy();
Optional<BasicAuthenticationInterceptor> basicAuthenticationInterceptor = Optional.empty();
if (proxyProperties != null && Strings.hasText(proxyProperties.getHost()) && proxyProperties.getPort() > 0) {
proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyProperties.getHost(), proxyProperties.getPort()));
if (Strings.hasText(proxyProperties.getUsername()) && Strings.hasText(proxyProperties.getPassword())) {
basicAuthenticationInterceptor = Optional.of(new BasicAuthenticationInterceptor(proxyProperties.getUsername(), proxyProperties.getPassword()));
}
} else {
proxy = Proxy.NO_PROXY;
}
RestTemplate restTemplate = new RestTemplate(Arrays.asList(new FormHttpMessageConverter(), new OAuth2AccessTokenResponseHttpMessageConverter(), new StringHttpMessageConverter()));
restTemplate.getInterceptors().add(new UserAgentRequestInterceptor());
basicAuthenticationInterceptor.ifPresent(restTemplate.getInterceptors()::add);
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
requestFactory.setProxy(proxy);
restTemplate.setRequestFactory(requestFactory);
return restTemplate;
}
use of com.okta.spring.boot.oauth.http.UserAgentRequestInterceptor in project okta-spring-boot by okta.
the class OktaOAuth2UserService method restOperations.
private RestOperations restOperations() {
RestTemplate restTemplate = new RestTemplate();
restTemplate.setErrorHandler(new OAuth2ErrorResponseErrorHandler());
restTemplate.getInterceptors().add(new UserAgentRequestInterceptor());
return restTemplate;
}
Aggregations