use of com.google.api.client.json.webtoken.JsonWebToken.Payload in project styx by spotify.
the class GoogleIdTokenAuth method jwtPayload.
private static Payload jwtPayload(String targetAudience, String serviceAccountId, String tokenServerUrl) {
final Payload payload = new Payload();
final long currentTime = System.currentTimeMillis();
payload.put("target_audience", targetAudience);
payload.setIssuer(serviceAccountId);
payload.setAudience(tokenServerUrl);
payload.setIssuedAtTimeSeconds(currentTime / 1000);
payload.setExpirationTimeSeconds(currentTime / 1000 + 3600);
return payload;
}
use of com.google.api.client.json.webtoken.JsonWebToken.Payload in project google-auth-library-java by googleapis.
the class ComputeEngineCredentialsTest method idTokenWithAudience_full.
@Test
@SuppressWarnings("unchecked")
void idTokenWithAudience_full() throws IOException {
MockMetadataServerTransportFactory transportFactory = new MockMetadataServerTransportFactory();
ComputeEngineCredentials credentials = ComputeEngineCredentials.newBuilder().setHttpTransportFactory(transportFactory).build();
String targetAudience = "https://foo.bar";
IdTokenCredentials tokenCredential = IdTokenCredentials.newBuilder().setIdTokenProvider(credentials).setTargetAudience(targetAudience).setOptions(Arrays.asList(IdTokenProvider.Option.FORMAT_FULL)).build();
tokenCredential.refresh();
Payload p = tokenCredential.getIdToken().getJsonWebSignature().getPayload();
assertTrue(p.containsKey("google"), "Full ID Token format not provided");
ArrayMap<String, ArrayMap> googleClaim = (ArrayMap<String, ArrayMap>) p.get("google");
assertTrue(googleClaim.containsKey("compute_engine"));
}
use of com.google.api.client.json.webtoken.JsonWebToken.Payload in project google-auth-library-java by googleapis.
the class ImpersonatedCredentialsTest method idTokenWithAudience_withEmail.
@Test
void idTokenWithAudience_withEmail() throws IOException {
mockTransportFactory.transport.setTargetPrincipal(IMPERSONATED_CLIENT_EMAIL);
mockTransportFactory.transport.setAccessToken(ACCESS_TOKEN);
mockTransportFactory.transport.setExpireTime(getDefaultExpireTime());
ImpersonatedCredentials targetCredentials = ImpersonatedCredentials.create(sourceCredentials, IMPERSONATED_CLIENT_EMAIL, null, IMMUTABLE_SCOPES_LIST, VALID_LIFETIME, mockTransportFactory);
mockTransportFactory.transport.setIdToken(TOKEN_WITH_EMAIL);
String targetAudience = "https://foo.bar";
IdTokenCredentials tokenCredential = IdTokenCredentials.newBuilder().setIdTokenProvider(targetCredentials).setTargetAudience(targetAudience).setOptions(Arrays.asList(IdTokenProvider.Option.INCLUDE_EMAIL)).build();
tokenCredential.refresh();
assertEquals(TOKEN_WITH_EMAIL, tokenCredential.getAccessToken().getTokenValue());
Payload p = tokenCredential.getIdToken().getJsonWebSignature().getPayload();
assertTrue(p.containsKey("email"));
}
Aggregations