use of com.google.auth.oauth2.AccessToken in project vertx-auth by vert-x3.
the class AuthCodeImpl method getToken.
/**
* Returns the Access Token object.
*
* @param params - code: Authorization code (from previous step).
* redirectURI: A String that represents the callback uri.
* @param handler - The handler returning the results.
*/
@Override
public void getToken(JsonObject params, Handler<AsyncResult<AccessToken>> handler) {
getToken("authorization_code", 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));
});
}
use of com.google.auth.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));
});
}
use of com.google.auth.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();
}
use of com.google.auth.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();
}
use of com.google.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);
}
}
Aggregations