use of com.google.api.client.googleapis.auth.oauth2.GoogleIdToken.Payload in project google-api-java-client by google.
the class GoogleIdTokenTest method testDeprecatedMethods.
@SuppressWarnings("deprecation")
public void testDeprecatedMethods() {
Payload payload = newPayload(USER_ID, CLIENT_ID);
assertEquals(USER_ID, payload.getUserId());
assertEquals(CLIENT_ID, payload.getIssuee());
payload.setUserId(ANOTHER_USER_ID);
payload.setIssuee(ANOTHER_CLIENT_ID);
assertEquals(ANOTHER_USER_ID, payload.getUserId());
assertEquals(ANOTHER_CLIENT_ID, payload.getIssuee());
assertEquals(ANOTHER_USER_ID, payload.getSubject());
assertEquals(ANOTHER_CLIENT_ID, payload.getAuthorizedParty());
}
use of com.google.api.client.googleapis.auth.oauth2.GoogleIdToken.Payload in project pratilipi by Pratilipi.
the class GoogleApi method getUserData.
public static UserData getUserData(String googleIdToken) throws InvalidArgumentException, UnexpectedServerException {
try {
GoogleIdToken idToken = UxModeFilter.isAndroidApp() ? getAndroidIdTokenVerifier().verify(googleIdToken) : getWebIdTokenVerifier().verify(googleIdToken);
String authorisedParty = UxModeFilter.isAndroidApp() ? getAppClientId() : getWebClientId();
if (idToken == null || idToken.getPayload() == null || !idToken.getPayload().getAuthorizedParty().equals(authorisedParty)) {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("googleIdToken", "Invalid GoogleIdToken !");
throw new InvalidArgumentException(jsonObject);
}
Payload payload = idToken.getPayload();
logger.log(Level.INFO, "GoogleApi Payload : " + new Gson().toJson(payload));
if (payload.get("given_name") == null || ((String) payload.get("given_name")).isEmpty()) {
logger.log(Level.SEVERE, "Google given_name is missing for GoogleUser: " + payload.getSubject());
throw new UnexpectedServerException();
}
UserData userData = new UserData();
userData.setGoogleId(payload.getSubject());
userData.setFirstName((String) payload.get("given_name"));
userData.setLastName((String) payload.get("family_name"));
userData.setEmail(payload.getEmail());
return userData;
} catch (GeneralSecurityException | IOException e) {
logger.log(Level.SEVERE, "Google id token verification failed: " + e);
throw new UnexpectedServerException();
}
}
use of com.google.api.client.googleapis.auth.oauth2.GoogleIdToken.Payload in project google-api-java-client by google.
the class GoogleIdTokenTest method newPayload.
private static Payload newPayload(String userId, String clientId) {
Payload payload = new Payload();
payload.setIssuer("accounts.google.com");
payload.setAudience(clientId);
payload.setAuthorizedParty(clientId);
payload.setSubject(userId);
payload.setExpirationTimeSeconds(100L);
payload.setIssuedAtTimeSeconds(0L);
return payload;
}
use of com.google.api.client.googleapis.auth.oauth2.GoogleIdToken.Payload in project endpoints-java by cloudendpoints.
the class GoogleJwtAuthenticatorTest method setUp.
@Before
public void setUp() throws Exception {
payload = new Payload();
payload.setAuthorizedParty(CLIENT_ID);
payload.setAudience(AUDIENCE);
payload.setEmail(EMAIL);
payload.setSubject(USER_ID);
authenticator = new GoogleJwtAuthenticator(verifier);
request = new MockHttpServletRequest();
attr = Attribute.from(request);
attr.set(Attribute.API_METHOD_CONFIG, config);
attr.set(Attribute.ENABLE_CLIENT_ID_WHITELIST, true);
request.addHeader(GoogleAuth.AUTHORIZATION_HEADER, "Bearer " + TOKEN);
when(token.getPayload()).thenReturn(payload);
}
Aggregations