spring-social / spring-social-google

Spring Social extension with connection support and an API binding for Google

Home Page:https://spring-social-google.github.io/spring-social-google/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

providerServiceId comes back as email

walterh opened this issue · comments

In GoogleAdapter fetchUserProfile:

        .setUsername(profile.getId())

Because this is what's used to create the providerServiceId in:

protected String extractProviderUserId(AccessGrant accessGrant) {
    Google api = ((GoogleServiceProvider)getServiceProvider()).getApi(accessGrant.getAccessToken());
    UserProfile userProfile = getApiAdapter().fetchUserProfile(api);
    return userProfile.getUsername();
}

Hi!
I am encountering the same problem.
I previously used spring-social-google-1.0.0.M1 and things were working great. Since I upgraded to 1.0.0.M3 my project breaks when trying to fetch a social profile using the userProviderId.
In fact I believe that if you want to override the method
protected String extractProviderUserId(AccessGrant accessGrant)
in your GoogleConnectionFactory you should return Google's unique user ID (numerical value) and not the email which according to google is not the actual user id.
See : https://developers.google.com/accounts/docs/OAuth2Login#obtainuserinfo

  An identifier for the user, unique among all Google accounts and never reused. A Google account can have
  multiple emails at different points in time, but this value is never changed. You should use this within your 
  application as the unique-identifier key for the user.

I'm not sure you can get to that userId in the first api call so maybe you should just leave it to null == not override extractProviderUserId in OAuth2ConnectionFactory.

Thanks.