Search in sources :

Example 66 with AccessToken

use of com.microsoft.identity.common.internal.providers.oauth2.AccessToken in project vertx-auth by vert-x3.

the class PasswordImpl method getToken.

/**
 * Returns the Access Token object.
 *
 * @param params - username: A string that represents the registered username.
 *                 password: A string that represents the registered password.
 *                 scope:    A String that represents the application privileges.
 * @param handler - The handler function returning the results.
 */
@Override
public void getToken(JsonObject params, Handler<AsyncResult<AccessToken>> handler) {
    getToken("password", params, res -> {
        if (res.failed()) {
            handler.handle(Future.failedFuture(res.cause()));
            return;
        }
        AccessToken token;
        try {
            token = new OAuth2TokenImpl(provider, res.result());
        } catch (RuntimeException e) {
            handler.handle(Future.failedFuture(e));
            return;
        }
        handler.handle(Future.succeededFuture(token));
    });
}
Also used : AccessToken(io.vertx.ext.auth.oauth2.AccessToken) OAuth2TokenImpl(io.vertx.ext.auth.oauth2.impl.OAuth2TokenImpl)

Example 67 with AccessToken

use of com.microsoft.identity.common.internal.providers.oauth2.AccessToken in project vertx-auth by vert-x3.

the class OAuth2AccessTokenTest method tokenShouldNotBeExpired.

@Test
public void tokenShouldNotBeExpired() {
    config = oauthConfig;
    oauth2.authenticate(tokenConfig, res -> {
        if (res.failed()) {
            fail(res.cause().getMessage());
        } else {
            AccessToken token = (AccessToken) res.result();
            assertFalse(token.expired());
            testComplete();
        }
    });
    await();
}
Also used : AccessToken(io.vertx.ext.auth.oauth2.AccessToken) Test(org.junit.Test)

Example 68 with AccessToken

use of com.microsoft.identity.common.internal.providers.oauth2.AccessToken in project vertx-auth by vert-x3.

the class OAuth2AccessTokenTest method tokenShouldBeExpiredWhenExpirationDateIsInThePast.

@Test
public void tokenShouldBeExpiredWhenExpirationDateIsInThePast() {
    config = oauthConfig;
    oauth2.authenticate(tokenConfig, res -> {
        if (res.failed()) {
            fail(res.cause().getMessage());
        } else {
            AccessToken token = (AccessToken) res.result();
            // hack the token to set the expires_at (to yesterday)
            token.principal().put("expires_at", System.currentTimeMillis() - 24 * 60 * 60 * 1000);
            assertTrue(token.expired());
            testComplete();
        }
    });
    await();
}
Also used : AccessToken(io.vertx.ext.auth.oauth2.AccessToken) Test(org.junit.Test)

Example 69 with AccessToken

use of com.microsoft.identity.common.internal.providers.oauth2.AccessToken in project docker-client by spotify.

the class ContainerRegistryAuthSupplierTest method testAuthForImage_TokenWithoutExpirationDoesNotCauseRefresh.

@Test
public void testAuthForImage_TokenWithoutExpirationDoesNotCauseRefresh() throws Exception {
    final AccessToken accessToken = new AccessToken(tokenValue, null);
    final GoogleCredentials credentials = new GoogleCredentials(accessToken);
    final ContainerRegistryAuthSupplier supplier = new ContainerRegistryAuthSupplier(credentials, clock, TimeUnit.SECONDS.toMillis(minimumExpirationSecs), refresher);
    assertThat(supplier.authFor("gcr.io/foobar/barfoo:latest"), matchesAccessToken(accessToken));
    verify(refresher, never()).refresh(credentials);
}
Also used : AccessToken(com.google.auth.oauth2.AccessToken) GoogleCredentials(com.google.auth.oauth2.GoogleCredentials) Test(org.junit.Test)

Example 70 with AccessToken

use of com.microsoft.identity.common.internal.providers.oauth2.AccessToken in project docker-client by spotify.

the class ContainerRegistryAuthSupplier method authFor.

@Override
public RegistryAuth authFor(final String imageName) throws DockerException {
    final String[] imageParts = imageName.split("/", 2);
    if (imageParts.length < 2 || !GCR_REGISTRIES.contains(imageParts[0])) {
        // not an image on GCR
        return null;
    }
    final AccessToken accessToken;
    try {
        accessToken = getAccessToken();
    } catch (IOException e) {
        throw new DockerException(e);
    }
    return authForAccessToken(accessToken);
}
Also used : DockerException(com.spotify.docker.client.exceptions.DockerException) AccessToken(com.google.auth.oauth2.AccessToken) IOException(java.io.IOException)

Aggregations

AccessToken (com.google.auth.oauth2.AccessToken)78 Test (org.junit.Test)44 GoogleCredentials (com.google.auth.oauth2.GoogleCredentials)33 Date (java.util.Date)23 IOException (java.io.IOException)20 AccessToken (io.vertx.ext.auth.oauth2.AccessToken)16 Instant (java.time.Instant)10 Client (javax.ws.rs.client.Client)10 AccessToken (org.glassfish.jersey.client.oauth1.AccessToken)10 ConsumerCredentials (org.glassfish.jersey.client.oauth1.ConsumerCredentials)10 JsonObject (io.vertx.core.json.JsonObject)9 URI (java.net.URI)9 Feature (javax.ws.rs.core.Feature)8 JerseyTest (org.glassfish.jersey.test.JerseyTest)8 MockHttpTransport (com.google.api.client.testing.http.MockHttpTransport)6 ServiceAccountCredentials (com.google.auth.oauth2.ServiceAccountCredentials)6 Credential (io.cdap.cdap.proto.security.Credential)6 InputStreamReader (java.io.InputStreamReader)6 Clock (java.time.Clock)6 WebTarget (javax.ws.rs.client.WebTarget)6