use of io.vertx.ext.auth.oauth2.AccessToken in project docker-client by spotify.
the class ContainerRegistryAuthSupplier method authForBuild.
@Override
public RegistryConfigs authForBuild() throws DockerException {
final AccessToken accessToken;
try {
accessToken = getAccessToken();
} catch (IOException e) {
// do not fail as the GCR access token may not be necessary for building the image currently
// being built
log.warn("unable to get access token for Google Container Registry, " + "configuration for building image will not contain RegistryAuth for GCR", e);
return RegistryConfigs.empty();
}
final Map<String, RegistryAuth> configs = new HashMap<>(GCR_REGISTRIES.size());
for (String serverName : GCR_REGISTRIES) {
configs.put(serverName, authForAccessToken(accessToken));
}
return RegistryConfigs.create(configs);
}
use of io.vertx.ext.auth.oauth2.AccessToken in project docker-client by spotify.
the class ContainerRegistryAuthSupplierTest method testAuthForBuild_TokenWithoutExpirationDoesNotCauseRefresh.
@Test
public void testAuthForBuild_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);
final RegistryConfigs configs = supplier.authForBuild();
assertThat(configs.configs().values(), is(not(empty())));
assertThat(configs.configs().values(), everyItem(matchesAccessToken(accessToken)));
verify(refresher, never()).refresh(credentials);
}
use of io.vertx.ext.auth.oauth2.AccessToken in project docker-client by spotify.
the class ContainerRegistryAuthSupplierTest method testAuthForSwarm_TokenWithoutExpirationDoesNotCauseRefresh.
@Test
public void testAuthForSwarm_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.authForSwarm(), matchesAccessToken(accessToken));
verify(refresher, never()).refresh(credentials);
}
use of io.vertx.ext.auth.oauth2.AccessToken in project api-framework by vinscom.
the class LoadUserFromSessionRouteBuillder method handle.
public void handle(RoutingContext pRoutingContext) {
Session session = pRoutingContext.session();
if (session != null && getOAuth2Auth() != null) {
JsonObject principal = session.get(FrameworkConstants.Session.PRINCIPAL);
if (principal != null) {
OAuth2AuthProviderImpl provider = (OAuth2AuthProviderImpl) getOAuth2Auth().getDelegate();
try {
OAuth2TokenImpl token = new OAuth2TokenImpl(provider, principal);
pRoutingContext.setUser(new AccessToken(token));
} catch (RuntimeException e) {
getLog().error(e);
pRoutingContext.fail(401);
return;
}
}
}
pRoutingContext.next();
}
use of io.vertx.ext.auth.oauth2.AccessToken in project vertx-auth by vert-x3.
the class OAuth2IntrospectTest method introspectAccessToken.
@Test
public void introspectAccessToken() {
config = oauthIntrospect;
fixture = fixtureIntrospect;
oauth2.introspectToken(token, res -> {
if (res.failed()) {
fail(res.cause().getMessage());
} else {
AccessToken token = res.result();
assertNotNull(token);
JsonObject principal = token.principal();
// clean time specific value
principal.remove("expires_at");
principal.remove("access_token");
final JsonObject assertion = fixtureIntrospect.copy();
assertEquals(assertion.getMap(), principal.getMap());
token.isAuthorized("scopeB", res0 -> {
if (res0.failed()) {
fail(res0.cause().getMessage());
} else {
if (res0.result()) {
testComplete();
} else {
fail("Should be allowed");
}
}
});
}
});
await();
}
Aggregations