use of io.vertx.reactivex.ext.auth.oauth2.AccessToken in project java by kubernetes-client.
the class GCPAuthenticatorTest method testRefreshApplicationDefaultCredentials.
@Test
public void testRefreshApplicationDefaultCredentials() {
Date fakeTokenExpiryDate = Date.from(Instant.parse(fakeTokenExpiry));
Mockito.when(mockGC.getAccessToken()).thenReturn(new AccessToken(fakeToken, fakeTokenExpiryDate));
final Map<String, Object> config = new HashMap<String, Object>() {
};
final Map<String, Object> result = gcpAuthenticator.refresh(config);
assertEquals(fakeToken, result.get(GCPAuthenticator.ACCESS_TOKEN));
assertEquals(fakeTokenExpiryDate, result.get(GCPAuthenticator.EXPIRY));
}
use of io.vertx.reactivex.ext.auth.oauth2.AccessToken in project curiostack by curioswitch.
the class AbstractAccessTokenProvider method refresh.
private CompletableFuture<AccessToken> refresh(Type type) {
return fetchToken(type).handle((msg, t) -> {
if (t != null) {
throw new IllegalStateException("Failed to refresh GCP access token.", t);
}
final TokenResponse response;
try {
response = OBJECT_MAPPER.readValue(msg.content().array(), TokenResponse.class);
} catch (IOException e) {
throw new UncheckedIOException("Error parsing token refresh response.", e);
}
long expiresAtMilliseconds = clock.millis() + TimeUnit.SECONDS.toMillis(response.expiresIn());
return new AccessToken(type == Type.ID_TOKEN ? response.idToken() : response.accessToken(), new Date(expiresAtMilliseconds));
});
}
use of io.vertx.reactivex.ext.auth.oauth2.AccessToken in project grpc-java by grpc.
the class GoogleAuthLibraryCallCredentialsTest method serviceAccountWithScopeNotToJwt.
@Test
public void serviceAccountWithScopeNotToJwt() throws Exception {
final AccessToken token = new AccessToken("allyourbase", new Date(Long.MAX_VALUE));
KeyPair pair = KeyPairGenerator.getInstance("RSA").generateKeyPair();
ServiceAccountCredentials credentials = new ServiceAccountCredentials(null, "email@example.com", pair.getPrivate(), null, Arrays.asList("somescope")) {
@Override
public AccessToken refreshAccessToken() {
return token;
}
};
GoogleAuthLibraryCallCredentials callCredentials = new GoogleAuthLibraryCallCredentials(credentials);
callCredentials.applyRequestMetadata(method, attrs, executor, applier);
assertEquals(1, 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));
}
use of io.vertx.reactivex.ext.auth.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);
}
use of io.vertx.reactivex.ext.auth.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);
}
Aggregations