Using Python-social-auth the social user is not installed in the pipeline
AttributeError at /complete/google-oauth2/
'NoneType' object has no attribute 'provider'
This happens with a new or already registered user on this line https://github.com/omab/python-social-auth/blob/master/social/actions.py#L69 and is a new issue. It showed up when I was playing with a custom pipeline, but it worked before, now falling back to the most basic set of python-social-auth doesn't work.
Even with a reloaded database and updated syncdb. (This is Django 1.4.20, an old project that we are updating).
The problem is obvious, wherever in the pipeline the default social user needs to be set to user doesn't work, but I don't understand the python-social-auth code very well and am going round and round here.Any pointers or help would be much appreciated here.
500 that appears in my stack trace if it helps.
[23/Jul/2015 12:00:32] "GET /complete/google-oauth2/?state=MRFnOQG6Cv5Cmb1xqdcp53C33dDrFf7C&code=4/2bgjgYgxFtqB2c10BInigkigGfy4ZNOSYBqyHBUdLGo&authuser=0&prompt=consent&session_state=4c6c24bdd3100a506c4744be8ab9b793ed6399d5..a5f9 HTTP/1.1" 500 148571
This is the data that the code clamps, obviously because some previous part of the pipeline does not put the user "social_user" into the user. But I don't know where it would go wrong, could anyone more familiar with this suggest any suggestions on which the default pipeline might terminate?
partial None
is_authenticated False
args ()
is_new False
redirect_value ''
user <User: 4o5bb5o5>
social_user None
kwargs {}
login <function _do_login at 0xaef3de9c>
backend <social.backends.google.GoogleOAuth2 object at 0x9e68fac>
data <QueryDict: {u'state': [u'dwMOHkBxsVgvj4mwL54LXqihzJVYMWTV'], u'code': [u'4/fjOVlVyAK5mS_mcv7uHVWQsFycpjlbB_YOy4F7omIIY'], u'prompt': [u'none'], u'session_state': [u'ab65081ee8e4a3720d5963deced4cabc7b259a85..8f10'], u'authuser': [u'0']}>
redirect_name
'next'
When I go to the home page, I am logged in with a gmail account. (Although some of the post_save functions that should happen after create_user are not triggered, but I assume that since it crashed in the middle of the pipeline). Then when I log out and back on again, it crashes again on the same page.
source to share
It may be too late, but it will help others. I have used this in my custom application.
As shown here ,
ID_KEY
installed None
And here I have seen with pdb ID_KEY
installed id
. Naturally, this structure expects to id
be one of the response keys from the server in time user_data
.
This my custom backend looks like this:
class CustomOAuth2(BaseOAuth2):
"""Custom OAuth authentication backend"""
name = 'Custom'
ID_KEY = 'email' #<===== SET THIS TO UNIQUE ATTRIBUTE IF ID IS NOT RETURNED
AUTHORIZATION_URL = 'https://auth.Custom.org/oauth2/authorize'
ACCESS_TOKEN_URL = 'https://auth.Custom.org/oauth2/token'
ACCESS_TOKEN_METHOD = 'POST'
REVOKE_TOKEN_URL = '= https://auth.Custom.org/oauth2/revoke'
REVOKE_TOKEN_METHOD = 'POST'
USER_DATA_URL = "https://api.Custom.org/user/"
SCOPE_SEPARATOR = ','
def get_user_details(self, response):
"""Return user details from Custom account"""
return {'username': response.get('login'),
'email': response.get('email') or '',
'first_name': response.get('name')}
def user_data(self, access_token, *args, **kwargs):
"""Loads user data from service"""
try:
headers = {'Authorization': 'Bearer %s' %access_token}
headers['Accept'] = 'application/json'
response = requests.get(self.USER_DATA_URL, headers=headers)
d = json.loads(response.content)
return d
except ValueError:
return None
source to share