Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for java Proxy with basic auth #266

Merged
merged 5 commits into from
Jun 4, 2020
Merged

Add support for java Proxy with basic auth #266

merged 5 commits into from
Jun 4, 2020

Conversation

lbalmaceda
Copy link
Contributor

@lbalmaceda lbalmaceda commented Jun 2, 2020

Changes

This PR adds a new constructor for both AuthAPI and ManagementAPI classes that accepts a set of ClientOptions (final name can still change).

The idea is that from now on, every new property that we want to configure in the OkHttpClient comes through this options object. This way, we reduce the exposure of third-party classes in our public API.

For now, this Options object accepts a ProxyOptions object (final name also subject to change), that will hold the Proxy instance and any basic authentication, if required.

Usage

Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("localhost", 9090));
ProxyOptions proxyOptions = new ProxyOptions(proxy);
//proxyOptions.setBasicAuthentication("johndoe", "psswd".toCharArray()); //- Optional
HttpOptions httpOptions = new HttpOptions();
httpOptions.setProxyOptions(proxyOptions);

AuthAPI api = new AuthAPI(DOMAIN, CLIENT_ID, CLIENT_SECRET, httpOptions);

Local environment setup

In order to test the SDK with a Proxy, I've followed these steps to set up a local proxy:

  1. Download proxyman or any other proxy that supports authentication.
  2. Enable the Proxy. Browser requests should be blocked for now.
  3. Whitelist the proxy certificate in the keychain and trust it. Proxyman offers a helper tool to do this for you when provided with the root password. Browser requests should start coming through the proxy now.
  4. Whitelist the proxy certificate in the JVM and trust it. I've achieved this with the following command:
sudo keytool -keystore ${JAVA_HOME}/jre/lib/security/cacerts -storepass changeit -import -trustcacerts -v -alias {alias}CA -file {certificate}.pem

Create a class or test to try the code snippet in the section above. Requests made by classes, like tests, should now come through.

References

The feature was originally requested here #91

Testing

  • This change adds test coverage
  • This change has been tested on the latest version of the platform/language or why not

Checklist

@lbalmaceda lbalmaceda marked this pull request as ready for review June 2, 2020 23:54
@lbalmaceda lbalmaceda requested a review from a team June 2, 2020 23:54
@jimmyjames jimmyjames requested review from jimmyjames and removed request for a team June 3, 2020 16:14
Copy link
Contributor

@jimmyjames jimmyjames left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some minor feedback, mostly around JavaDocs. Otherwise this looks good.

Regarding the names, I think ClientOptions and ProxyOptions are appropriate. Were there other names you were considering that you want to raise for discussion?

One other question I have is if/how you tested the proxy support (aside from the unit tests that rely on mocks)?

src/main/java/com/auth0/client/ClientOptions.java Outdated Show resolved Hide resolved
src/main/java/com/auth0/client/ProxyOptions.java Outdated Show resolved Hide resolved
src/main/java/com/auth0/client/mgmt/ManagementAPI.java Outdated Show resolved Hide resolved
@lbalmaceda lbalmaceda merged commit e99aa8b into master Jun 4, 2020
@lbalmaceda lbalmaceda deleted the add-proxy branch June 4, 2020 21:39
@lbalmaceda lbalmaceda modified the milestones: v1-Next, 1.19.0 Jun 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants