Search in sources :

Example 6 with Payload

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;
}
Also used : Payload(com.google.api.client.json.webtoken.JsonWebToken.Payload)

Example 7 with 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"));
}
Also used : ArrayMap(com.google.api.client.util.ArrayMap) Payload(com.google.api.client.json.webtoken.JsonWebToken.Payload) Test(org.junit.jupiter.api.Test)

Example 8 with Payload

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"));
}
Also used : Payload(com.google.api.client.json.webtoken.JsonWebToken.Payload) Test(org.junit.jupiter.api.Test)

Aggregations

Payload (com.google.api.client.json.webtoken.JsonWebToken.Payload)8 Test (org.junit.jupiter.api.Test)6 ArrayMap (com.google.api.client.util.ArrayMap)4 RefreshTokenRequest (com.google.api.client.auth.oauth2.RefreshTokenRequest)1 TokenRequest (com.google.api.client.auth.oauth2.TokenRequest)1 TokenResponse (com.google.api.client.auth.oauth2.TokenResponse)1 GenericUrl (com.google.api.client.http.GenericUrl)1 Header (com.google.api.client.json.webtoken.JsonWebSignature.Header)1