use of com.google.api.client.googleapis.auth.oauth2.GoogleIdToken.Payload in project data-transfer-project by google.
the class GoogleAuthDataGenerator method generateAuthData.
@Override
public AuthData generateAuthData(String callbackBaseUrl, String authCode, String id, AuthData initialAuthData, String extra) {
Preconditions.checkState(initialAuthData == null, "Earlier auth data not expected for Google flow");
AuthorizationCodeFlow flow;
TokenResponse response;
try {
flow = createFlow();
response = flow.newTokenRequest(authCode).setRedirectUri(// TODO(chuy): Parameterize
callbackBaseUrl + redirectPath).execute();
} catch (IOException e) {
throw new RuntimeException("Error calling AuthorizationCodeFlow.execute ", e);
}
// Figure out storage
Credential credential = null;
try {
credential = flow.createAndStoreCredential(response, id);
} catch (IOException e) {
throw new RuntimeException("Error calling AuthorizationCodeFlow.createAndStoreCredential ", e);
}
// GoogleIdToken.Payload payload = ((GoogleTokenResponse) response).parseIdToken().getPayload();
return new TokensAndUrlAuthData(credential.getAccessToken(), credential.getRefreshToken(), credential.getTokenServerEncodedUrl());
}
use of com.google.api.client.googleapis.auth.oauth2.GoogleIdToken.Payload in project data-transfer-project by google.
the class GoogleAuth method generateAuthData.
@Override
public AuthData generateAuthData(String callbackBaseUrl, String authCode, UUID jobId, @Nullable AuthData initialAuthData, @Nullable String extra) throws IOException {
Preconditions.checkState(initialAuthData == null, "Earlier auth data not expected for Google flow");
AuthorizationCodeFlow flow = createFlow();
TokenResponse response = flow.newTokenRequest(authCode).setRedirectUri(// TODO(chuy): Parameterize
callbackBaseUrl + CALLBACK_PATH).execute();
// Figure out storage
Credential credential = flow.createAndStoreCredential(response, jobId.toString());
// GoogleIdToken.Payload payload = ((GoogleTokenResponse) response).parseIdToken().getPayload();
return toAuthData(credential);
}
use of com.google.api.client.googleapis.auth.oauth2.GoogleIdToken.Payload in project google-api-java-client by google.
the class GoogleIdTokenVerifierTest method newPayload.
private static Payload newPayload(String clientId) {
Payload payload = new Payload();
payload.setIssuer("accounts.google.com");
payload.setAudience(clientId);
payload.setAuthorizedParty(clientId);
payload.setExpirationTimeSeconds(100L);
payload.setIssuedAtTimeSeconds(0L);
return payload;
}
use of com.google.api.client.googleapis.auth.oauth2.GoogleIdToken.Payload in project google-api-java-client by google.
the class GoogleIdTokenVerifierTest method testVerify.
public void testVerify() throws Exception {
GoogleIdTokenVerifier verifier = new GoogleIdTokenVerifier.Builder(new GooglePublicKeysManagerTest.PublicCertsMockHttpTransport(), new JacksonFactory()).build();
Header header = new Header();
header.setAlgorithm("RS25");
Payload payload = newPayload(CLIENT_ID);
Payload payload2 = newPayload(CLIENT_ID + "2");
GoogleIdToken idToken = new GoogleIdToken(header, payload, new byte[0], new byte[0]);
GoogleIdToken idToken2 = new GoogleIdToken(header, payload2, new byte[0], new byte[0]);
assertFalse(verifier.verify(idToken));
assertFalse(verifier.verify(idToken2));
verifier = new GoogleIdTokenVerifier(new GooglePublicKeysManagerTest.PublicCertsMockHttpTransport(), new JacksonFactory());
assertFalse(verifier.verify(idToken));
assertFalse(verifier.verify(idToken2));
// TODO(yanivi): add a unit test that returns true
}
use of com.google.api.client.googleapis.auth.oauth2.GoogleIdToken.Payload in project google-api-java-client by google.
the class GoogleIdTokenTest method testEmailVerified.
public void testEmailVerified() {
Payload payload = newPayload(USER_ID, CLIENT_ID);
assertNull(payload.getEmailVerified());
payload.setEmailVerified(true);
assertTrue(payload.getEmailVerified());
payload.setEmailVerified(false);
assertFalse(payload.getEmailVerified());
payload.setEmailVerified(null);
assertNull(payload.getEmailVerified());
payload.set(EMAIL_VERIFIED_KEY, "true");
assertTrue(payload.getEmailVerified());
payload.set(EMAIL_VERIFIED_KEY, true);
assertTrue(payload.getEmailVerified());
payload.set(EMAIL_VERIFIED_KEY, "false");
assertFalse(payload.getEmailVerified());
payload.set(EMAIL_VERIFIED_KEY, false);
assertFalse(payload.getEmailVerified());
payload.set(EMAIL_VERIFIED_KEY, "RandomString");
assertFalse(payload.getEmailVerified());
payload.set(EMAIL_VERIFIED_KEY, "");
assertFalse(payload.getEmailVerified());
payload.set(EMAIL_VERIFIED_KEY, null);
assertNull(payload.getEmailVerified());
// Wrong type.
payload.set(EMAIL_VERIFIED_KEY, new Integer(5));
try {
payload.getEmailVerified();
fail();
} catch (ClassCastException e) {
// Expected.
}
}
Aggregations