Search in sources :

Example 16 with HttpOptions

use of com.auth0.client.HttpOptions in project auth0-java by auth0.

the class AuthAPITest method shouldUseConfiguredTimeoutValues.

@Test
public void shouldUseConfiguredTimeoutValues() {
    HttpOptions options = new HttpOptions();
    options.setConnectTimeout(20);
    options.setReadTimeout(30);
    AuthAPI api = new AuthAPI(DOMAIN, CLIENT_ID, CLIENT_SECRET, options);
    assertThat(api.getClient().connectTimeoutMillis(), is(20 * 1000));
    assertThat(api.getClient().readTimeoutMillis(), is(30 * 1000));
}
Also used : HttpOptions(com.auth0.client.HttpOptions) Test(org.junit.Test)

Example 17 with HttpOptions

use of com.auth0.client.HttpOptions in project auth0-java-mvc-common by auth0.

the class AuthenticationControllerTest method shouldCreateAuthAPIClientWithCustomHttpOptions.

@Test
public void shouldCreateAuthAPIClientWithCustomHttpOptions() {
    HttpOptions options = new HttpOptions();
    options.setConnectTimeout(5);
    options.setReadTimeout(6);
    ArgumentCaptor<HttpOptions> captor = ArgumentCaptor.forClass(HttpOptions.class);
    AuthenticationController.Builder spy = spy(AuthenticationController.newBuilder("domain", "clientId", "clientSecret").withHttpOptions(options));
    spy.build();
    verify(spy).createAPIClient(eq("domain"), eq("clientId"), eq("clientSecret"), captor.capture());
    HttpOptions actual = captor.getValue();
    assertThat(actual, is(notNullValue()));
    assertThat(actual.getConnectTimeout(), is(5));
    assertThat(actual.getReadTimeout(), is(6));
}
Also used : HttpOptions(com.auth0.client.HttpOptions) Test(org.junit.jupiter.api.Test)

Example 18 with HttpOptions

use of com.auth0.client.HttpOptions in project auth0-java by auth0.

the class AuthAPI method buildNetworkingClient.

/**
 * Given a set of options, it creates a new instance of the {@link OkHttpClient}
 * configuring them according to their availability.
 *
 * @param options the options to set to the client.
 * @return a new networking client instance configured as requested.
 */
private OkHttpClient buildNetworkingClient(HttpOptions options) {
    OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder();
    final ProxyOptions proxyOptions = options.getProxyOptions();
    if (proxyOptions != null) {
        // Set proxy
        clientBuilder.proxy(proxyOptions.getProxy());
        // Set authentication, if present
        final String proxyAuth = proxyOptions.getBasicAuthentication();
        if (proxyAuth != null) {
            clientBuilder.proxyAuthenticator(new Authenticator() {

                private static final String PROXY_AUTHORIZATION_HEADER = "Proxy-Authorization";

                @Override
                public okhttp3.Request authenticate(Route route, Response response) throws IOException {
                    if (response.request().header(PROXY_AUTHORIZATION_HEADER) != null) {
                        return null;
                    }
                    return response.request().newBuilder().header(PROXY_AUTHORIZATION_HEADER, proxyAuth).build();
                }
            });
        }
    }
    configureLogging(options.getLoggingOptions());
    Dispatcher dispatcher = new Dispatcher();
    dispatcher.setMaxRequests(options.getMaxRequests());
    dispatcher.setMaxRequestsPerHost(options.getMaxRequestsPerHost());
    return clientBuilder.addInterceptor(logging).addInterceptor(telemetry).connectTimeout(options.getConnectTimeout(), TimeUnit.SECONDS).readTimeout(options.getReadTimeout(), TimeUnit.SECONDS).dispatcher(dispatcher).build();
}
Also used : PasswordlessSmsResponse(com.auth0.json.auth.PasswordlessSmsResponse) PasswordlessEmailResponse(com.auth0.json.auth.PasswordlessEmailResponse) ProxyOptions(com.auth0.client.ProxyOptions) Request(com.auth0.net.Request) IOException(java.io.IOException)

Example 19 with HttpOptions

use of com.auth0.client.HttpOptions in project auth0-java by auth0.

the class ManagementAPITest method shouldUseConfiguredMaxRequests.

@Test
public void shouldUseConfiguredMaxRequests() {
    HttpOptions options = new HttpOptions();
    options.setMaxRequests(10);
    ManagementAPI api = new ManagementAPI(DOMAIN, API_TOKEN, options);
    assertThat(api.getClient().dispatcher().getMaxRequests(), is(10));
}
Also used : HttpOptions(com.auth0.client.HttpOptions) Test(org.junit.Test)

Example 20 with HttpOptions

use of com.auth0.client.HttpOptions in project auth0-java by auth0.

the class ManagementAPITest method shouldConfigureHeaderLoggingFromOptions.

@Test
public void shouldConfigureHeaderLoggingFromOptions() {
    LoggingOptions loggingOptions = new LoggingOptions(LoggingOptions.LogLevel.HEADERS);
    Set<String> headersToRedact = new HashSet<>();
    headersToRedact.add("Authorization");
    headersToRedact.add("Cookie");
    loggingOptions.setHeadersToRedact(headersToRedact);
    HttpOptions options = new HttpOptions();
    options.setLoggingOptions(loggingOptions);
    ManagementAPI api = new ManagementAPI(DOMAIN, API_TOKEN, options);
    assertThat(api.getClient().interceptors(), hasItem(isA(HttpLoggingInterceptor.class)));
    for (Interceptor i : api.getClient().interceptors()) {
        if (i instanceof HttpLoggingInterceptor) {
            HttpLoggingInterceptor logging = (HttpLoggingInterceptor) i;
            assertThat(logging.getLevel(), is(Level.HEADERS));
        }
    }
}
Also used : HttpOptions(com.auth0.client.HttpOptions) LoggingOptions(com.auth0.client.LoggingOptions) TelemetryInterceptor(com.auth0.net.TelemetryInterceptor) RateLimitInterceptor(com.auth0.net.RateLimitInterceptor) HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor) HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

HttpOptions (com.auth0.client.HttpOptions)31 Test (org.junit.Test)29 HttpLoggingInterceptor (okhttp3.logging.HttpLoggingInterceptor)9 LoggingOptions (com.auth0.client.LoggingOptions)8 ProxyOptions (com.auth0.client.ProxyOptions)8 RateLimitInterceptor (com.auth0.net.RateLimitInterceptor)6 Proxy (java.net.Proxy)6 okhttp3 (okhttp3)6 TelemetryInterceptor (com.auth0.net.TelemetryInterceptor)5 Request (com.auth0.net.Request)3 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)2 Test (org.junit.jupiter.api.Test)2 PasswordlessEmailResponse (com.auth0.json.auth.PasswordlessEmailResponse)1 PasswordlessSmsResponse (com.auth0.json.auth.PasswordlessSmsResponse)1