Search in sources :

Example 31 with AccessToken

use of io.vertx.ext.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 32 with AccessToken

use of io.vertx.ext.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 33 with AccessToken

use of io.vertx.ext.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)

Example 34 with AccessToken

use of io.vertx.ext.auth.oauth2.AccessToken in project java by kubernetes-client.

the class KubeConfigTest method testGCPAuthProviderExpiredTokenWithoutGCloud.

@Test
public void testGCPAuthProviderExpiredTokenWithoutGCloud() {
    String gcpConfigExpiredToken = "apiVersion: v1\n" + "contexts:\n" + "- context:\n" + "    user: gke-cluster\n" + "  name: foo-context\n" + "current-context: foo-context\n" + "users:\n" + "- name: gke-cluster\n" + "  user:\n" + "    auth-provider:\n" + "      config:\n" + "        access-token: fake-token\n" + "        expiry: 1970-01-01T00:00:00Z\n" + "      name: gcp";
    String fakeToken = "new-fake-token";
    String fakeTokenExpiry = "2121-08-05T02:30:24Z";
    GoogleCredentials mockGC = Mockito.mock(GoogleCredentials.class);
    Mockito.when(mockGC.getAccessToken()).thenReturn(new AccessToken(fakeToken, Date.from(Instant.parse(fakeTokenExpiry))));
    KubeConfig.registerAuthenticator(new GCPAuthenticator(null, mockGC));
    try {
        KubeConfig kc = KubeConfig.loadKubeConfig(new StringReader(gcpConfigExpiredToken));
        assertEquals(fakeToken, kc.getAccessToken());
    } catch (Exception ex) {
        ex.printStackTrace();
        fail("Unexpected exception: " + ex);
    }
}
Also used : GCPAuthenticator(io.kubernetes.client.util.authenticators.GCPAuthenticator) AccessToken(com.google.auth.oauth2.AccessToken) StringReader(java.io.StringReader) GoogleCredentials(com.google.auth.oauth2.GoogleCredentials) IOException(java.io.IOException) Test(org.junit.Test)

Example 35 with AccessToken

use of io.vertx.ext.auth.oauth2.AccessToken in project api-framework by vinscom.

the class LoadUserFromAccessTokenRouteBuillder method handle.

public void handle(RoutingContext pRoutingContext) {
    if (pRoutingContext.user() == null) {
        String access_token = pRoutingContext.request().getHeader(HttpHeaders.AUTHORIZATION);
        if (!Strings.isNullOrEmpty(access_token)) {
            OAuth2AuthProviderImpl provider = (OAuth2AuthProviderImpl) getOAuth2Auth().getDelegate();
            JsonObject accessToken = new JsonObject().put("access_token", access_token.split(" ")[1]);
            try {
                OAuth2TokenImpl token = new OAuth2TokenImpl(provider, accessToken);
                pRoutingContext.setUser(new AccessToken(token));
            } catch (RuntimeException e) {
                getLog().error(e);
                pRoutingContext.fail(401);
                return;
            }
        }
    }
    pRoutingContext.next();
}
Also used : AccessToken(io.vertx.reactivex.ext.auth.oauth2.AccessToken) JsonObject(io.vertx.core.json.JsonObject) OAuth2AuthProviderImpl(io.vertx.ext.auth.oauth2.impl.OAuth2AuthProviderImpl) OAuth2TokenImpl(io.vertx.ext.auth.oauth2.impl.OAuth2TokenImpl)

Aggregations

Test (org.junit.Test)25 AccessToken (com.google.auth.oauth2.AccessToken)22 JsonObject (io.vertx.core.json.JsonObject)13 AccessToken (io.vertx.ext.auth.oauth2.AccessToken)13 Date (java.util.Date)10 IOException (java.io.IOException)9 OAuth2TokenImpl (io.vertx.ext.auth.oauth2.impl.OAuth2TokenImpl)8 GoogleCredentials (com.google.auth.oauth2.GoogleCredentials)7 OAuth2Credentials (com.google.auth.oauth2.OAuth2Credentials)5 OAuth2Response (io.vertx.ext.auth.oauth2.OAuth2Response)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 ServiceAccountCredentials (com.google.auth.oauth2.ServiceAccountCredentials)3 Buffer (io.vertx.core.buffer.Buffer)3 URI (java.net.URI)3 WebTarget (javax.ws.rs.client.WebTarget)3