omab / python-social-auth

Social auth made simple
http://psa.matiasaguirre.net
BSD 3-Clause "New" or "Revised" License
2.83k stars 1.09k forks source link

Django: type(social_user.extra_data) == unicode #898

Closed codeleta closed 8 years ago

codeleta commented 8 years ago

Hello!

code:

social_user = get_object_or_none(
       self.request.user.social_auth.all(),
       provider='vk-oauth2'
)
strategy = load_strategy(self.request)
print type(social_user.extra_data)
social_user.refresh_token(strategy)

traceback:

in 0.2.16 version

<type 'unicode'>
Internal Server Error: /user-photos/load/vk-oauth2/
Traceback (most recent call last):
  File "/home/user/.virtualenvs/papara/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 149, in get_response
    response = self.process_exception_by_middleware(e, request)
  File "/home/user/.virtualenvs/papara/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 147, in get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/user/.virtualenvs/papara/local/lib/python2.7/site-packages/django/views/generic/base.py", line 68, in view
    return self.dispatch(request, *args, **kwargs)
  File "/home/user/.virtualenvs/papara/local/lib/python2.7/site-packages/django/views/generic/base.py", line 88, in dispatch
    return handler(request, *args, **kwargs)
  File "/home/user/.virtualenvs/papara/local/lib/python2.7/site-packages/django/views/generic/base.py", line 157, in get
    context = self.get_context_data(**kwargs)
  File "/home/user/papara/apps/user_photos/views.py", line 329, in get_context_data
    social_user.refresh_token(strategy)
  File "/home/user/.virtualenvs/papara/local/lib/python2.7/site-packages/social/storage/base.py", line 49, in refresh_token
    token = self.extra_data.get('refresh_token') or \
AttributeError: 'unicode' object has no attribute 'get'

in 0.2.14 version

<type 'dict'>
  File "/home/user/.virtualenvs/papara/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 149, in get_response
    response = self.process_exception_by_middleware(e, request)
  File "/home/user/.virtualenvs/papara/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 147, in get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/user/.virtualenvs/papara/local/lib/python2.7/site-packages/django/views/generic/base.py", line 68, in view
    return self.dispatch(request, *args, **kwargs)
  File "/home/user/.virtualenvs/papara/local/lib/python2.7/site-packages/django/views/generic/base.py", line 88, in dispatch
    return handler(request, *args, **kwargs)
  File "/home/user/.virtualenvs/papara/local/lib/python2.7/site-packages/django/views/generic/base.py", line 157, in get
    context = self.get_context_data(**kwargs)
  File "/home/user/papara/apps/user_photos/views.py", line 329, in get_context_data
    social_user.refresh_token(strategy)
  File "/home/user/.virtualenvs/papara/local/lib/python2.7/site-packages/social/storage/base.py", line 54, in refresh_token
    response = backend.refresh_token(token, *args, **kwargs)
  File "/home/user/.virtualenvs/papara/local/lib/python2.7/site-packages/social/backends/oauth.py", line 418, in refresh_token
    request = self.request(url, **request_args)
  File "/home/user/.virtualenvs/papara/local/lib/python2.7/site-packages/social/backends/base.py", line 225, in request
    response.raise_for_status()
  File "/home/user/.virtualenvs/papara/local/lib/python2.7/site-packages/requests/models.py", line 837, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
HTTPError: 401 Client Error: Unauthorized for url: https://oauth.vk.com/access_token

psa send request vk.com: https://oauth.vk.com/access_token?client_id=<>&client_secret=<>&grant_type=refresh_token&refresh_token=<> in 0.2.14 vk response: {"error":"invalid_grant","error_description":"Code is invalid or expired."} vk get access_token docs I think, "code" param miss

in 0.2.14 facebook and odnoklassniki refresh_token is OK.

codeleta commented 8 years ago

extra_data fixed in Pull Request #897. Error in vk.com refresh_token stay.

troygrosfield commented 8 years ago

same issue here. Will be nice to get that PR merged in.

youcandanch commented 8 years ago

@omab just a heads up that this is currently breaking a good amount of stuff using refresh token in mainline - any chance this could get a set of eyes and a version bump on pypi?

youcandanch commented 8 years ago

@troygrosfield @Cotest it's been merged in and 0.2.18 is on PyPi now. Thanks, @omab!

bcfurtado commented 8 years ago

Still experiencing the same issue here though. Using version 0.2.18 with Django==1.6.11

troygrosfield commented 8 years ago

This is still breaking for me as well with 0.2.18 and django==1.9.5.

clintonb commented 8 years ago

The default value of JSONField is incorrectly set to the string value '{}' instead of a dict, {}. See https://github.com/omab/python-social-auth/blob/master/social/apps/django_app/default/fields.py#L20.