From efc5979c1d7f85bce8781a21086db98691ce0fa0 Mon Sep 17 00:00:00 2001 From: Angelica Ochoa Date: Fri, 1 Feb 2019 17:11:37 -0500 Subject: [PATCH] Use OAuth2Operations to fetch User email. Signed-off-by: Angelica Ochoa --- .../GoogleplusConnectionFactory.java | 36 +++++++++---------- 1 file changed, 16 insertions(+), 20 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..60f325ce428 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,9 +32,9 @@ 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.api.oauth2.OAuth2Operations; import org.springframework.social.google.connect.GoogleAdapter; import org.springframework.social.google.connect.GoogleServiceProvider; import org.springframework.social.oauth2.AccessGrant; @@ -43,24 +43,20 @@ * */ 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(); + } }