Skip to content

Commit

Permalink
Use OAuth2Operations to fetch User email.
Browse files Browse the repository at this point in the history
Signed-off-by: Angelica Ochoa <[email protected]>
  • Loading branch information
ao508 committed Feb 1, 2019
1 parent cfeba87 commit efc5979
Showing 1 changed file with 16 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -43,24 +43,20 @@
*
*/
public class GoogleplusConnectionFactory extends OAuth2ConnectionFactory<Google> {



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();
}
}

0 comments on commit efc5979

Please sign in to comment.