Search in sources :

Example 16 with Credentials

use of okhttp3.Credentials in project JavaSDK by OpenGamma.

the class BasicTest method testAuthGoodHttpFactory.

public void testAuthGoodHttpFactory() {
    AuthClient mockAuth = new TestingAuthClient();
    try (ServiceInvoker invoker = ServiceInvoker.builder(CREDENTIALS).httpClientFactory(builder -> builder.addInterceptor(chain -> chain.proceed(chain.request())).followRedirects(false).build()).authClientFactory(inv -> mockAuth).build()) {
        assertEquals(invoker.getServiceUrl(), SERVICE_URL);
        // logging, user-agent & auth plus one from test
        assertEquals(invoker.getHttpClient().interceptors().size(), 4);
        assertEquals(invoker.getHttpClient().followRedirects(), false);
    }
}
Also used : AuthenticationException(com.opengamma.sdk.common.auth.AuthenticationException) Credentials(com.opengamma.sdk.common.auth.Credentials) Request(okhttp3.Request) OkHttpClient(okhttp3.OkHttpClient) SERVICE_URL(com.opengamma.sdk.common.ServiceInvoker.SERVICE_URL) Assert.assertThrows(org.testng.Assert.assertThrows) AuthClient(com.opengamma.sdk.common.auth.AuthClient) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) AuthClient(com.opengamma.sdk.common.auth.AuthClient)

Example 17 with Credentials

use of okhttp3.Credentials in project JavaSDK by OpenGamma.

the class BasicTest method testAuthGoodHttpClient.

public void testAuthGoodHttpClient() {
    AuthClient mockAuth = new TestingAuthClient();
    try (ServiceInvoker invoker = ServiceInvoker.builder(CREDENTIALS).httpClient(new OkHttpClient()).authClientFactory(inv -> mockAuth).build()) {
        assertEquals(invoker.getServiceUrl(), SERVICE_URL);
        // user-agent & auth
        assertEquals(invoker.getHttpClient().interceptors().size(), 2);
    }
}
Also used : AuthenticationException(com.opengamma.sdk.common.auth.AuthenticationException) Credentials(com.opengamma.sdk.common.auth.Credentials) Request(okhttp3.Request) OkHttpClient(okhttp3.OkHttpClient) SERVICE_URL(com.opengamma.sdk.common.ServiceInvoker.SERVICE_URL) Assert.assertThrows(org.testng.Assert.assertThrows) AuthClient(com.opengamma.sdk.common.auth.AuthClient) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) OkHttpClient(okhttp3.OkHttpClient) AuthClient(com.opengamma.sdk.common.auth.AuthClient)

Example 18 with Credentials

use of okhttp3.Credentials in project mbed-cloud-sdk-java by ARMmbed.

the class HttpBasicAuth method intercept.

@Override
public Response intercept(Chain chain) throws IOException {
    Request request = chain.request();
    // If the request already have an authorization (eg. Basic auth), do nothing
    if (request.header("Authorization") == null) {
        String credentials = Credentials.basic(username, password);
        request = request.newBuilder().addHeader("Authorization", credentials).build();
    }
    return chain.proceed(request);
}
Also used : Request(okhttp3.Request)

Example 19 with Credentials

use of okhttp3.Credentials in project mbed-cloud-sdk-java by ARMmbed.

the class HttpBasicAuth method intercept.

@Override
public Response intercept(Chain chain) throws IOException {
    Request request = chain.request();
    // If the request already have an authorization (eg. Basic auth), do nothing
    if (request.header("Authorization") == null) {
        String credentials = Credentials.basic(username, password);
        request = request.newBuilder().addHeader("Authorization", credentials).build();
    }
    return chain.proceed(request);
}
Also used : Request(okhttp3.Request)

Example 20 with Credentials

use of okhttp3.Credentials in project mbed-cloud-sdk-java by ARMmbed.

the class HttpBasicAuth method intercept.

@Override
public Response intercept(Chain chain) throws IOException {
    Request request = chain.request();
    // If the request already have an authorization (eg. Basic auth), do nothing
    if (request.header("Authorization") == null) {
        String credentials = Credentials.basic(username, password);
        request = request.newBuilder().addHeader("Authorization", credentials).build();
    }
    return chain.proceed(request);
}
Also used : Request(okhttp3.Request)

Aggregations

Request (okhttp3.Request)39 Response (okhttp3.Response)29 OkHttpClient (okhttp3.OkHttpClient)22 IOException (java.io.IOException)20 Test (org.junit.Test)16 HttpUrl (okhttp3.HttpUrl)10 RequestBody (okhttp3.RequestBody)9 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)9 ResponseBody (okhttp3.ResponseBody)8 NonNull (androidx.annotation.NonNull)7 MockResponse (okhttp3.mockwebserver.MockResponse)7 BasicAuthenticator (com.burgstaller.okhttp.basic.BasicAuthenticator)6 CachingAuthenticator (com.burgstaller.okhttp.digest.CachingAuthenticator)6 Credentials (com.burgstaller.okhttp.digest.Credentials)6 DigestAuthenticator (com.burgstaller.okhttp.digest.DigestAuthenticator)6 Observable (rx.Observable)6 AuthenticationCacheInterceptor (com.burgstaller.okhttp.AuthenticationCacheInterceptor)5 CachingAuthenticatorDecorator (com.burgstaller.okhttp.CachingAuthenticatorDecorator)5 PokemonGo (com.pokegoapi.api.PokemonGo)5 PtcCredentialProvider (com.pokegoapi.auth.PtcCredentialProvider)5