use of okhttp3.Authenticator in project edx-app-android by edx.
the class AuthenticationTests method testAuthenticate_withoutRefreshToken.
@Test
public void testAuthenticate_withoutRefreshToken() throws Exception {
loginPrefs.storeAuthTokenResponse(MockDataUtil.getMockResponse("post_oauth2_access_token_no_refresh_token", AuthResponse.class), LoginPrefs.AuthBackend.PASSWORD);
client = client.newBuilder().authenticator(new OauthRefreshTokenAuthenticator(context)).build();
Request request = new Request.Builder().url(mockServer.url("/dummy/endpoint/")).header("Authorization", "expired_token").build();
Response response = client.newCall(request).execute();
assertEquals(HttpStatus.UNAUTHORIZED, response.code());
assertEquals("expired_token", response.request().header("Authorization"));
}
use of okhttp3.Authenticator in project okhttp-digest by rburgst.
the class AuthenticationCacheInterceptorTest method givenCachedAuthenticationFor.
private void givenCachedAuthenticationFor(String url, Map<String, CachingAuthenticator> authCache) throws IOException {
Authenticator decorator = new CachingAuthenticatorDecorator(new BasicAuthenticator(new Credentials("user1", "user1")), authCache);
Request dummyRequest = new Request.Builder().url(url).get().build();
Response response = new Response.Builder().request(dummyRequest).protocol(Protocol.HTTP_1_1).code(HTTP_UNAUTHORIZED).message("Unauthorized").header("WWW-Authenticate", "Basic realm=\"myrealm\"").build();
decorator.authenticate(null, response);
}
use of okhttp3.Authenticator in project okhttp-digest by rburgst.
the class DispatchingAuthenticatorTest method testCaching_withBasicAuthenticatorPreferredOrder.
@Test
public void testCaching_withBasicAuthenticatorPreferredOrder() throws Exception {
final Credentials credentials = new Credentials("user", "pwd");
final BasicAuthenticator basicAuthenticator = new BasicAuthenticator(credentials);
final DigestAuthenticator digestAuthenticator = new DigestAuthenticator(credentials);
DispatchingAuthenticator authenticator = new DispatchingAuthenticator.Builder().with("basic", basicAuthenticator).with("digest", digestAuthenticator).build();
Request request = authenticator.authenticate(mockRoute, createUnauthorizedServerResponse());
assertNotNull(request);
request = authenticator.authenticateWithState(mockRoute, createDummyRequest());
assertNotNull(request);
}
use of okhttp3.Authenticator in project okhttp-digest by rburgst.
the class DispatchingAuthenticatorTest method testCaching_withDigestAuthenticatorPreferredOrder.
@Test
public void testCaching_withDigestAuthenticatorPreferredOrder() throws Exception {
final Credentials credentials = new Credentials("user", "pwd");
final BasicAuthenticator basicAuthenticator = new BasicAuthenticator(credentials);
final DigestAuthenticator digestAuthenticator = new DigestAuthenticator(credentials);
DispatchingAuthenticator authenticator = new DispatchingAuthenticator.Builder().with("digest", digestAuthenticator).with("basic", basicAuthenticator).build();
Request request = authenticator.authenticate(mockRoute, createUnauthorizedServerResponse());
assertNotNull(request);
String authorizationHeader = request.header("Authorization");
assertThat(authorizationHeader, CoreMatchers.startsWith("Basic"));
request = authenticator.authenticateWithState(mockRoute, createDummyRequest());
assertNotNull(request);
}
use of okhttp3.Authenticator in project okhttp-digest by rburgst.
the class ProxyAuthenticationManualTest method testConnection_WithProxyDigestAuthWithNotAllowdSites_Expect403.
@Test
public void testConnection_WithProxyDigestAuthWithNotAllowdSites_Expect403() throws IOException {
final DigestAuthenticator authenticator = givenDigestAuthenticator();
final OkHttpClient client = givenHttpClientWithProxyAuth(authenticator);
final Request request = new Request.Builder().url("http://www.youtube.com").build();
Response response = client.newCall(request).execute();
assertEquals(403, response.code());
}
Aggregations