From 76a462b1e47f69dad81eadd5e9d0652bdd3c4cc7 Mon Sep 17 00:00:00 2001 From: Angelica Ochoa Date: Mon, 11 Feb 2019 11:59:59 -0500 Subject: [PATCH] Use OAuth2Operations to fetch user email Signed-off-by: Angelica Ochoa --- .../GoogleplusConnectionFactory.java | 34 +++++++++---------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/security/security-spring/src/main/java/org/cbioportal/security/spring/authentication/googleplus/GoogleplusConnectionFactory.java b/security/security-spring/src/main/java/org/cbioportal/security/spring/authentication/googleplus/GoogleplusConnectionFactory.java index 4a62f9d1dd5..f40256881bb 100644 --- a/security/security-spring/src/main/java/org/cbioportal/security/spring/authentication/googleplus/GoogleplusConnectionFactory.java +++ b/security/security-spring/src/main/java/org/cbioportal/security/spring/authentication/googleplus/GoogleplusConnectionFactory.java @@ -32,35 +32,33 @@ package org.cbioportal.security.spring.authentication.googleplus; -import org.springframework.social.connect.UserProfile; import org.springframework.social.connect.support.OAuth2ConnectionFactory; import org.springframework.social.google.api.Google; import org.springframework.social.google.connect.GoogleAdapter; import org.springframework.social.google.connect.GoogleServiceProvider; import org.springframework.social.oauth2.AccessGrant; +import org.springframework.social.google.api.oauth2.OAuth2Operations; + /** * @author criscuof * */ public class GoogleplusConnectionFactory extends OAuth2ConnectionFactory { - - - - public GoogleplusConnectionFactory(String clientId, String clientSecret) { - super("google", new GoogleServiceProvider(clientId, clientSecret), - new GoogleAdapter()); - } - /* - * modification of original factory class to support using the user's email address as his/her id - * original method utilized the google id, a numeric string - */ - @Override - protected String extractProviderUserId(AccessGrant accessGrant) { - Google api = ((GoogleServiceProvider)getServiceProvider()).getApi(accessGrant.getAccessToken()); - UserProfile userProfile = getApiAdapter().fetchUserProfile(api); - return userProfile.getEmail(); - } + public GoogleplusConnectionFactory(String clientId, String clientSecret) { + super("google", new GoogleServiceProvider(clientId, clientSecret), + new GoogleAdapter()); + } + /** + * modification of original factory class to support using the user's email address as his/her id + * original method utilized the google id, a numeric string + */ + @Override + protected String extractProviderUserId(AccessGrant accessGrant) { + Google api = ((GoogleServiceProvider)getServiceProvider()).getApi(accessGrant.getAccessToken()); + OAuth2Operations op = api.oauth2Operations(); + return op.getUserinfo().getEmail(); + } }