use of io.vertx.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);
}
use of io.vertx.ext.auth.oauth2.AccessToken in project google-auth-library-java by google.
the class AppEngineCredentialsTest method refreshAccessToken_sameAs.
@Test
public void refreshAccessToken_sameAs() throws IOException {
final String expectedAccessToken = "ExpectedAccessToken";
MockAppIdentityService appIdentity = new MockAppIdentityService();
appIdentity.setAccessTokenText(expectedAccessToken);
appIdentity.setExpiration(new Date(System.currentTimeMillis() + 60L * 60L * 100L));
AppEngineCredentials credentials = AppEngineCredentials.newBuilder().setScopes(SCOPES).setAppIdentityService(appIdentity).build();
AccessToken accessToken = credentials.refreshAccessToken();
assertEquals(appIdentity.getAccessTokenText(), accessToken.getTokenValue());
assertEquals(appIdentity.getExpiration(), accessToken.getExpirationTime());
}
use of io.vertx.ext.auth.oauth2.AccessToken in project google-auth-library-java by google.
the class AppEngineCredentials method refreshAccessToken.
/**
* Refresh the access token by getting it from the App Identity service
*/
@Override
public AccessToken refreshAccessToken() throws IOException {
if (createScopedRequired()) {
throw new IOException("AppEngineCredentials requires createScoped call before use.");
}
GetAccessTokenResult accessTokenResponse = appIdentityService.getAccessToken(scopes);
String accessToken = accessTokenResponse.getAccessToken();
Date expirationTime = accessTokenResponse.getExpirationTime();
return new AccessToken(accessToken, expirationTime);
}
use of io.vertx.ext.auth.oauth2.AccessToken in project helios by spotify.
the class AuthenticatingHttpConnector method connect.
@Override
public HttpURLConnection connect(final URI uri, final String method, final byte[] entity, final Map<String, List<String>> headers) throws HeliosException {
final Endpoint endpoint = endpointIterator.next();
// convert the URI whose hostname portion is a domain name into a URI where the host is an IP
// as we expect there to be several different IP addresses besides a common domain name
final URI ipUri;
try {
ipUri = toIpUri(endpoint, uri);
} catch (URISyntaxException e) {
throw new HeliosException(e);
}
try {
log.debug("connecting to {}", ipUri);
final Optional<AccessToken> accessTokenOpt = accessTokenSupplier.get();
if (accessTokenOpt.isPresent()) {
final String token = accessTokenOpt.get().getTokenValue();
headers.put("Authorization", singletonList("Bearer " + token));
log.debug("Add Authorization header with bearer token");
}
if (clientCertificatePath.isPresent()) {
// prioritize using the certificate file if set
return connectWithCertificateFile(ipUri, method, entity, headers);
} else if (agentProxy.isPresent() && !identities.isEmpty()) {
// ssh-agent based authentication
return connectWithIdentities(identities, ipUri, method, entity, headers);
} else {
// no authentication
return doConnect(ipUri, method, entity, headers);
}
} catch (ConnectException | SocketTimeoutException | UnknownHostException e) {
// UnknownHostException happens if we can't resolve hostname into IP address.
// UnknownHostException's getMessage method returns just the hostname which is a
// useless message, so log the exception class name to provide more info.
log.debug(e.toString());
throw new HeliosException("Unable to connect to master: " + ipUri, e);
} catch (IOException e) {
throw new HeliosException("Unexpected error connecting to " + ipUri, e);
}
}
use of io.vertx.ext.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);
}
Aggregations