Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

fix for google users who haven't signed up to google plus #7

Merged
merged 1 commit into from

4 participants

@dannyclark

Hi,

I found that the google authentication page allows any google account to login but the 'plus' webservice fails for users who haven't signed up to google plus. So these users get errors with flask-social when they try to login with google.

The same information that is fetched from the 'plus' webservice can be retrieved from the 'oauth2' webservice instead. I've submitted a patch to do that.

You could argue that in the long run all google users will probably be forced to sign up for google plus account, but I'd argue right now that isn't the case, and the anomaly of being able to select an account and have it throw an error is a bad user experience.

Cheers,
Dan.

@mattupstate
Owner

This is a great addition. Really appreciate it!

@mattupstate mattupstate merged commit 4e27a14 into from
@halkeye

I see the comment "#add ' https://www.googleapis.com/auth/userinfo.email' to scope to also get email"
I assume thats a coding item, not an option?

import flask.ext.social.providers.google as google_social
google_social.config['request_token_params']['scope'] += " https://www.googleapis.com/auth/userinfo.email"

Looks to me like the data is fetched, but get_connection_values needs to be updated to return said values.
or would you recommend calling social.google.userinfo().get().execute() and manually fetching it yourself?

@dannyclark

Sorry that is a bit confusing: You're absolutely right, you'd need to change the code in get_connection_values to pass through the email address returned so it is just a coding hint rather than a usable option.

I initially had it in there (i.e. uncommented) before I realised it wasn't necessary for flask-social to work (and it's best to minimise the permissions that we're asking for the user for) so just left it as a comment in case anyone reading the code was wondering how to get the email address from google.

Should probably either take the comment out or make it a proper configurable option (if that makes sense for flask-social as a project - and if it's a popular enough option etc.)

@RayCLin

said "Google+ Sign-In works for all users with a Google account, whether or not they have upgraded to Google+."
https://developers.google.com/accounts/docs/OAuth2Login?hl=zh-TW

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 15 additions and 19 deletions.
  1. +15 −19 flask_social/providers/google.py
View
34 flask_social/providers/google.py
@@ -30,20 +30,24 @@
},
'request_token_params': {
'response_type': 'code',
- 'scope': 'https://www.googleapis.com/auth/plus.me'
+ 'scope': 'https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/plus.me'
+ #add ' https://www.googleapis.com/auth/userinfo.email' to scope to also get email
}
}
+def _get_api(credentials):
+ http = httplib2.Http()
+ http = credentials.authorize(http)
+ api = googleapi.build('oauth2', 'v2', http=http)
+ return api
+
def get_api(connection, **kwargs):
credentials = googleoauth.AccessTokenCredentials(
access_token=getattr(connection, 'access_token'),
user_agent=''
)
-
- http = httplib2.Http()
- http = credentials.authorize(http)
- return googleapi.build('plus', 'v1', http=http)
+ return _get_api(credentials)
def get_provider_user_id(response, **kwargs):
@@ -52,11 +56,7 @@ def get_provider_user_id(response, **kwargs):
access_token=response['access_token'],
user_agent=''
)
-
- http = httplib2.Http()
- http = credentials.authorize(http)
- api = googleapi.build('plus', 'v1', http=http)
- profile = api.people().get(userId='me').execute()
+ profile = _get_api(credentials).userinfo().get().execute()
return profile['id']
return None
@@ -72,17 +72,13 @@ def get_connection_values(response, **kwargs):
user_agent=''
)
- http = httplib2.Http()
- http = credentials.authorize(http)
- api = googleapi.build('plus', 'v1', http=http)
- profile = api.people().get(userId='me').execute()
-
+ profile = _get_api(credentials).userinfo().get().execute()
return dict(
provider_id=config['id'],
provider_user_id=profile['id'],
access_token=access_token,
secret=None,
- display_name=profile['displayName'],
- profile_url=profile['url'],
- image_url=profile['image']['url']
- )
+ display_name=profile['name'],
+ profile_url=profile.get('link'),
+ image_url=profile.get('picture')
+ )
Something went wrong with that request. Please try again.