use of com.google.api.client.auth.openidconnect.IdTokenResponse in project google-oauth-java-client by googleapis.
the class CustomTokenRequestTest method testSetResponseClass.
public void testSetResponseClass() throws IOException {
TokenRequest request = new TokenRequest(new AccessTokenTransport(), JSON_FACTORY, AUTHORIZATION_SERVER_URL, "foo").setResponseClass(IdTokenResponse.class);
assertEquals(IdTokenResponse.class, request.getResponseClass());
TokenResponse response = request.execute();
assertTrue(response instanceof IdTokenResponse);
IdTokenResponse tokenResponse = (IdTokenResponse) response;
IdToken idToken = tokenResponse.parseIdToken();
assertEquals("John Doe", idToken.getPayload().get("name"));
}
use of com.google.api.client.auth.openidconnect.IdTokenResponse in project flytekit-java by flyteorg.
the class GoogleAuthHelper method getUserToken.
private Token getUserToken(UserCredentials credentials) throws IOException {
LOG.info("Fetching user id token for user credential: " + credentials.getClientId());
TokenRequest request = getRefreshTokenRequest(credentials);
Instant base = clock.instant();
IdTokenResponse response = request.executeUnparsed().parseAs(IdTokenResponse.class);
if (response == null || response.getIdToken() == null) {
String errMessage = String.format("Couldn't get id token for user credential: [%s].%n" + "UserCredentials can obtain an id token only when authenticated through " + "gcloud running 'gcloud auth login --update-adc' or " + "'gcloud auth application-default login'", credentials.getClientId());
throw new IOException(errMessage);
}
Instant expiryAt = base.plusSeconds(response.getExpiresInSeconds());
return Token.builder().accessToken(response.getIdToken()).expiry(expiryAt).tokenType(response.getTokenType()).build();
}
Aggregations