python-social-auth icon indicating copy to clipboard operation
python-social-auth copied to clipboard

AuthState missing for LinkedIn OAUTH2?

Open bertenator opened this issue 12 years ago • 7 comments

social.exceptions.AuthStateMissing AuthStateMissing: Session value state missing.

Traceback (most recent call last) File "/opt/a/virtualenvs/pyappd/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 255, in call response = self.get_response(request) File "/opt/a/virtualenvs/pyappd/lib/python2.7/site-packages/django/core/handlers/base.py", line 178, in get_response response = self.handle_uncaught_exception(request, resolver, sys.exc_info()) File "/opt/a/virtualenvs/pyappd/lib/python2.7/site-packages/django/core/handlers/base.py", line 115, in get_response response = callback(request, _callback_args, *_callback_kwargs) File "/opt/a/virtualenvs/pyappd/lib/python2.7/site-packages/django/views/decorators/csrf.py", line 77, in wrapped_view return view_func(_args, *_kwargs) File "/opt/a/virtualenvs/pyappd/lib/python2.7/site-packages/social/apps/django_app/utils.py", line 45, in wrapper return func(request, backend, _args, *_kwargs) File "/opt/a/virtualenvs/pyappd/lib/python2.7/site-packages/social/apps/django_app/views.py", line 21, in complete redirect_name=REDIRECT_FIELD_NAME, _args, *_kwargs) File "/opt/a/virtualenvs/pyappd/lib/python2.7/site-packages/social/actions.py", line 44, in do_complete _args, *_kwargs) File "/opt/a/virtualenvs/pyappd/lib/python2.7/site-packages/social/strategies/base.py", line 71, in complete return self.backend.auth_complete(_args, *_kwargs) File "/opt/a/virtualenvs/pyappd/lib/python2.7/site-packages/social/backends/oauth.py", line 345, in auth_complete data=self.auth_complete_params(self.validate_state()), File "/opt/a/virtualenvs/pyappd/lib/python2.7/site-packages/social/backends/oauth.py", line 307, in validate_state raise AuthStateMissing(self, 'state')

AuthStateMissing: Session value state missing.

I'm running into the above exception when trying to use linkedin OAUTH2. It seems like the following line is returning None:

self.strategy.session_get(self.name + '_state')

self.strategy <social.strategies.django_strategy.DjangoStrategy object at 0x5459390>

bertenator avatar Aug 21 '14 19:08 bertenator

+1 on this. I got the same exception sporadically for Linkedin OAuth2 backend. However, I can see the 'state" querystring was sent back from Linkedin server. Here is the log details:

Exception: <class 'social.exceptions.AuthStateMissing'>. Detail: Session value state missing.. UserId: Anonymous User. RequestUrl: www.securefer.com/complete/linkedin-oauth2/?code=AQT2WzYIie_EOsknru5bYY0OXxzLh0zaamLGi7vEvKnUTt89lLr5LT7n_-E_j42_oncXsO6-yoFs5q_dZwhg7E0nC1sIcjw_5blHRRR3t1AnZA-F238&state=wzM1cXZNYl6zK9TuGwDHVnOWapzA0pGK. RequestGet: <QueryDict: {u'state': [u'wzM1cXZNYl6zK9TuGwDHVnOWapzA0pGK'], u'code': [u'AQT2WzYIie_EOsknru5bYY0OXxzLh0zaamLGi7vEvKnUTt89lLr5LT7n_-E_j42_oncXsO6-yoFs5q_dZwhg7E0nC1sIcjw_5blHRRR3t1AnZA-F238']}>. RequestPost: <QueryDict: {}>. Callstack: Traceback (most recent call last): File "/home/ubuntu/virtualenvs/env/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 112, in get_response response = wrapped_callback(request, _callback_args, *_callback_kwargs) File "/home/ubuntu/virtualenvs/env/local/lib/python2.7/site-packages/django/views/decorators/csrf.py", line 57, in wrapped_view return view_func(_args, *_kwargs) File "/home/ubuntu/virtualenvs/env/local/lib/python2.7/site-packages/social/apps/django_app/utils.py", line 45, in wrapper return func(request, backend, _args, *_kwargs) File "/home/ubuntu/virtualenvs/env/local/lib/python2.7/site-packages/social/apps/django_app/views.py", line 21, in complete redirect_name=REDIRECT_FIELD_NAME, _args, *_kwargs) File "/home/ubuntu/virtualenvs/env/local/lib/python2.7/site-packages/social/actions.py", line 44, in do_complete _args, *_kwargs) File "/home/ubuntu/virtualenvs/env/local/lib/python2.7/site-packages/social/strategies/base.py", line 71, in complete return self.backend.auth_complete(_args, *_kwargs) File "/home/ubuntu/virtualenvs/env/local/lib/python2.7/site-packages/social/backends/oauth.py", line 345, in auth_complete data=self.auth_complete_params(self.validate_state()), File "/home/ubuntu/virtualenvs/env/local/lib/python2.7/site-packages/social/backends/oauth.py", line 307, in validate_state raise AuthStateMissing(self, 'state') AuthStateMissing: Session value state missing.

Appdevs-Moonlight avatar Aug 25 '14 21:08 Appdevs-Moonlight

+1 We have been getting the same error for LinkedIn sporadically as well. It's not predictable. It seems somewhere the session information is lost/modified, but we haven't been able to replicate the errors as well.

Just wanted to ask if it makes sense to build a small snippet to maybe restart the whole request response cycle in this case once more for this failure? I haven't as yet looked into the code fully in detail if this is possible or not, but hypothesis is that is the failure is a random event (specifically if the exception is AuthStateMissing) then when we encounter this let's just try to restart the whole process of auth request cycle. This essentially means that we are just trying to maximise our chances of getting a proper response (hopefully this random event will not repeat twice in a row). Let me know what do you guys think? Might try to test this out sometime soon, but have no clear way to reproduce this error as yet to test if this will work or not.

abhimskywalker avatar Apr 09 '15 08:04 abhimskywalker

i'm not sure if this is actually the same issue but I'm getting the error frequently (1/hour) and in my case it's apparently due to the user cancelling the request: this is what the query_dict looks like:

{u'state': [u'fsA5LYcwGuZaomUEsRJEi4g9iPavXtie'], u'error_description': [u'the user denied your request'], u'error': [u'access_denied']}

UPDATE: I can confirm that this happens every time a user denies the authorization - 100% repeatable.

pgcd avatar Apr 16 '15 07:04 pgcd

+1 on this I have seen the same behaviour as pgcd. Is there any workaround suggested?

craig-hacklaunch avatar May 05 '15 13:05 craig-hacklaunch

+1 I am also

liuminghao1 avatar Apr 30 '16 06:04 liuminghao1

Same here.

inakrin avatar Oct 02 '16 12:10 inakrin

The state was wrongly checking on error responses, masking the real error as an state missing one. Fixed by https://github.com/python-social-auth/social-core/commit/4d2903c1a26cc433731dcc103fd211a7a4716b96

omab avatar Dec 27 '16 13:12 omab