Skip to content

com.okta.spring.boot.oauth.OktaOAuth2ResourceServerAutoConfig#restTemplate unsets the proxy #503

@adrianbk

Description

@adrianbk

ℹ️ If you have a question, please post it on the Okta Developer Forum instead. Issues in this repository are reserved for bug reports and feature requests only.

I'm submitting a

  • bug report
  • feature request

Background info

Unable to use a JVM wide https proxy

Expected behavior

The jvm args -Dhttps.proxyHost=...., -Dhttps.proxyPort=3128 should be honoured and the proxy applied.

What went wrong?

The proxy is not used.

Steps to reproduce

It appears that setting proxy = Proxy.NO_PROXY; is causing the system-properties specified proxy to be ignored.

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

SDK Version

2.1.6

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions