Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use OAuth2Operations to fetch User email. #5677

Merged
merged 1 commit into from
Feb 11, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<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();
}

}