Search in sources :

Example 51 with AccessToken

use of com.google.auth.oauth2.AccessToken in project helios by spotify.

the class AuthenticatingHttpConnectorTest method createAuthenticatingConnectorWithAccessToken.

private AuthenticatingHttpConnector createAuthenticatingConnectorWithAccessToken(final Optional<AgentProxy> proxy, final List<Identity> identities) {
    final EndpointIterator endpointIterator = EndpointIterator.of(endpoints);
    final AccessToken accessToken = new AccessToken("<token>", null);
    return new AuthenticatingHttpConnector(USER, Suppliers.ofInstance(Optional.of(accessToken)), proxy, Optional.<CertKeyPaths>absent(), endpointIterator, connector, identities);
}
Also used : AccessToken(com.google.auth.oauth2.AccessToken)

Example 52 with AccessToken

use of com.google.auth.oauth2.AccessToken in project helios by spotify.

the class GoogleCredentialsAccessTokenSupplierTest method testGetWithStaticToken.

@Test
public void testGetWithStaticToken() {
    final AccessToken token = new AccessToken("token", null);
    final GoogleCredentialsAccessTokenSupplier supplier = new GoogleCredentialsAccessTokenSupplier(true, token, null);
    assertThat(supplier.get(), equalTo(Optional.of(token)));
}
Also used : AccessToken(com.google.auth.oauth2.AccessToken) Test(org.junit.Test)

Example 53 with AccessToken

use of com.google.auth.oauth2.AccessToken in project grpc-java by grpc.

the class GoogleAuthLibraryCallCredentialsTest method googleCredential_privacyAndIntegrityAllowed.

@Test
public void googleCredential_privacyAndIntegrityAllowed() {
    final AccessToken token = new AccessToken("allyourbase", new Date(Long.MAX_VALUE));
    final Credentials credentials = GoogleCredentials.create(token);
    GoogleAuthLibraryCallCredentials callCredentials = new GoogleAuthLibraryCallCredentials(credentials);
    callCredentials.applyRequestMetadata(new RequestInfoImpl(SecurityLevel.PRIVACY_AND_INTEGRITY), executor, applier);
    runPendingRunnables();
    verify(applier).apply(headersCaptor.capture());
    Metadata headers = headersCaptor.getValue();
    Iterable<String> authorization = headers.getAll(AUTHORIZATION);
    assertArrayEquals(new String[] { "Bearer allyourbase" }, Iterables.toArray(authorization, String.class));
}
Also used : AccessToken(com.google.auth.oauth2.AccessToken) Metadata(io.grpc.Metadata) Date(java.util.Date) Credentials(com.google.auth.Credentials) CallCredentials(io.grpc.CallCredentials) OAuth2Credentials(com.google.auth.oauth2.OAuth2Credentials) GoogleCredentials(com.google.auth.oauth2.GoogleCredentials) ServiceAccountCredentials(com.google.auth.oauth2.ServiceAccountCredentials) Test(org.junit.Test)

Example 54 with AccessToken

use of com.google.auth.oauth2.AccessToken in project grpc-java by grpc.

the class GoogleAuthLibraryCallCredentialsTest method googleCredential_integrityDenied.

@Test
public void googleCredential_integrityDenied() {
    final AccessToken token = new AccessToken("allyourbase", new Date(Long.MAX_VALUE));
    final Credentials credentials = GoogleCredentials.create(token);
    // Anything less than PRIVACY_AND_INTEGRITY should fail
    GoogleAuthLibraryCallCredentials callCredentials = new GoogleAuthLibraryCallCredentials(credentials);
    callCredentials.applyRequestMetadata(new RequestInfoImpl(SecurityLevel.INTEGRITY), executor, applier);
    runPendingRunnables();
    verify(applier).fail(statusCaptor.capture());
    Status status = statusCaptor.getValue();
    assertEquals(Status.Code.UNAUTHENTICATED, status.getCode());
}
Also used : Status(io.grpc.Status) AccessToken(com.google.auth.oauth2.AccessToken) Date(java.util.Date) Credentials(com.google.auth.Credentials) CallCredentials(io.grpc.CallCredentials) OAuth2Credentials(com.google.auth.oauth2.OAuth2Credentials) GoogleCredentials(com.google.auth.oauth2.GoogleCredentials) ServiceAccountCredentials(com.google.auth.oauth2.ServiceAccountCredentials) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)40 AccessToken (com.google.auth.oauth2.AccessToken)17 URI (java.net.URI)14 AccessToken (io.vertx.ext.auth.oauth2.AccessToken)13 MockTokenServerTransportFactory (com.google.auth.oauth2.GoogleCredentialsTest.MockTokenServerTransportFactory)12 OAuth2Credentials (com.google.auth.oauth2.OAuth2Credentials)8 JsonObject (io.vertx.core.json.JsonObject)8 Date (java.util.Date)8 OAuth2TokenImpl (io.vertx.ext.auth.oauth2.impl.OAuth2TokenImpl)7 GoogleCredentials (com.google.auth.oauth2.GoogleCredentials)6 MockHttpTransportFactory (com.google.auth.oauth2.GoogleCredentialsTest.MockHttpTransportFactory)6 IOException (java.io.IOException)5 Client (javax.ws.rs.client.Client)5 AccessToken (org.glassfish.jersey.client.oauth1.AccessToken)5 ConsumerCredentials (org.glassfish.jersey.client.oauth1.ConsumerCredentials)5 Metadata (io.grpc.Metadata)4 Feature (javax.ws.rs.core.Feature)4 JerseyTest (org.glassfish.jersey.test.JerseyTest)4 HttpRequest (com.google.api.client.http.HttpRequest)3 HttpRequestFactory (com.google.api.client.http.HttpRequestFactory)3