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

Yahoo backend handle key error #125

Closed
roberto-robles opened this issue Dec 9, 2013 · 2 comments
Closed

Yahoo backend handle key error #125

roberto-robles opened this issue Dec 9, 2013 · 2 comments

Comments

@roberto-robles
Copy link
Contributor

I am getting the following error:

Environment:

Request Method: GET
Request URL: http://localhost/api/social/complete/yahoo-oauth/?oauth_token=qgf9qgm&oauth_verifier=xqmcyd

Django Version: 1.6
Python Version: 2.7.3
Installed Applications:
('django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'corsheaders',
'yahoo_app')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'debug_toolbar.middleware.DebugToolbarMiddleware',
'corsheaders.middleware.CorsMiddleware',
'middleware.crossdomainxhr.XsSharing')

Traceback:
File "/home/lladmin/hanu_api/shared/env/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response

  1.                 response = wrapped_callback(request, _callback_args, *_callback_kwargs)
    
    File "/home/lladmin/hanu_api/shared/env/local/lib/python2.7/site-packages/django/views/decorators/csrf.py" in wrapped_view
  2.     return view_func(_args, *_kwargs)
    
    File "/home/lladmin/hanu_api/shared/env/local/lib/python2.7/site-packages/social/apps/django_app/utils.py" in wrapper
  3.         return func(request, backend, _args, *_kwargs)
    
    File "/home/lladmin/hanu_api/shared/env/local/lib/python2.7/site-packages/social/apps/django_app/views.py" in complete
  4.                    redirect_name=REDIRECT_FIELD_NAME, _args, *_kwargs)
    
    File "/home/lladmin/hanu_api/shared/env/local/lib/python2.7/site-packages/social/actions.py" in do_complete
  5.                              _args, *_kwargs)
    
    File "/home/lladmin/hanu_api/shared/env/local/lib/python2.7/site-packages/social/strategies/base.py" in complete
  6.     return self.backend.auth_complete(_args, *_kwargs)
    
    File "/home/lladmin/hanu_api/shared/env/local/lib/python2.7/site-packages/social/backends/oauth.py" in auth_complete
  7.     return self.do_auth(access_token, _args, *_kwargs)
    
    File "/home/lladmin/hanu_api/shared/env/local/lib/python2.7/site-packages/social/backends/oauth.py" in do_auth
  8.     return self.strategy.authenticate(_args, *_kwargs)
    
    File "/home/lladmin/hanu_api/shared/env/local/lib/python2.7/site-packages/social/strategies/django_strategy.py" in authenticate
  9.     return authenticate(_args, *_kwargs)
    
    File "/home/lladmin/hanu_api/shared/env/local/lib/python2.7/site-packages/django/contrib/auth/init.py" in authenticate
  10.         user = backend.authenticate(**credentials)
    
    File "/home/lladmin/hanu_api/shared/env/local/lib/python2.7/site-packages/social/backends/base.py" in authenticate
  11.     return self.pipeline(pipeline, _args, *_kwargs)
    
    File "/home/lladmin/hanu_api/shared/env/local/lib/python2.7/site-packages/social/backends/base.py" in pipeline
  12.     out = self.run_pipeline(pipeline, pipeline_index, _args, *_kwargs)
    
    File "/home/lladmin/hanu_api/shared/env/local/lib/python2.7/site-packages/social/backends/base.py" in run_pipeline
  13.         result = func(_args, *_out) or {}
    
    File "/home/lladmin/hanu_api/shared/env/local/lib/python2.7/site-packages/social/pipeline/social_auth.py" in social_details
  14. return {'details': strategy.backend.get_user_details(response)}
    
    File "/home/lladmin/hanu_api/shared/env/local/lib/python2.7/site-packages/social/backends/yahoo.py" in get_user_details
  15.         email = response.get('emails')[0]['handle']
    

Exception Type: KeyError at /social/complete/yahoo-oauth/
Exception Value: 'handle'

Above error comes because the response from yahoo contains a list with emails like the following:

response
{'access_token': {u'oauth_authorization_expires_in': u'_667',
u'oauth_expires_in': u'3600',
u'oauth_session_handle': u'_
_',
u'oauth_token': u'
__',
u'oauth_token_secret': u'
*_39b',
u'xoauth_yahoo_guid': u'
_6GM'},
u'created': u'2010-01-22T08:24:16Z',
u'emails': [{u'id': 1, u'type': u'HOME'},
{u'handle': u'
_
_ter@yahoo.com',
u'id': 2,
u'primary': True,
u'type': u'HOME'},
{u'id': 7, u'type': u'HOME'}],
u'familyName': u'
_****',
...}

I suggest iterate over the list of emails and check which element contains the handle key.

@roberto-robles
Copy link
Contributor Author

Btw if I use this Backend with a new Yahoo account the error is not raised, only with my Old Yahoo account.

Hope this can help, thanks for such great job with Python social auth.

@omab omab closed this as completed in 3131d77 Dec 10, 2013
@omab
Copy link
Owner

omab commented Dec 10, 2013

@roberto-robles, the change above should fix your issue. Thanks for the report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants