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

Toranodo Example Twitter Oauth

Open guruganesh26 opened this issue 12 years ago • 8 comments

Hi, Thanks for your help in previous issue.

In Toronado Python social auth, I tried with twiiter oauth, but it failed with following trace:

The same API Key, Secret key i am using with django example it works fine, but with toranado example, the pbm happens.

Please correct me, if i missed any configuration.

Traceback (most recent call last): File "/usr/local/lib/python2.7/dist-packages/tornado/web.py", line 1270, in _when_complete callback() File "/usr/local/lib/python2.7/dist-packages/tornado/web.py", line 1291, in _execute_method self._when_complete(method(_self.path_args, *_self.path_kwargs), File "/home/dinesh/Ganesh/python-social-auth/social/apps/tornado_app/handlers.py", line 22, in get self._auth(backend) File "/home/dinesh/Ganesh/python-social-auth/social/apps/tornado_app/utils.py", line 40, in wrapper return func(self, backend, _args, *_kwargs) File "/home/dinesh/Ganesh/python-social-auth/social/apps/tornado_app/handlers.py", line 29, in _auth do_auth(self.backend) File "/home/dinesh/Ganesh/python-social-auth/social/actions.py", line 25, in do_auth return backend.start() File "/home/dinesh/Ganesh/python-social-auth/social/backends/base.py", line 35, in start return self.strategy.redirect(self.auth_url()) File "/home/dinesh/Ganesh/python-social-auth/social/backends/oauth.py", line 154, in auth_url token = self.set_unauthorized_token() File "/home/dinesh/Ganesh/python-social-auth/social/backends/oauth.py", line 216, in set_unauthorized_token tokens = self.strategy.session_get(name, []) + [token] TypeError: unsupported operand type(s) for +: 'NoneType' and 'list'

guruganesh26 avatar Aug 08 '14 09:08 guruganesh26

@guruganesh26, try cleaning your cookies.

omab avatar Aug 09 '14 15:08 omab

Still the same problem :)

guruganesh26 avatar Aug 11 '14 09:08 guruganesh26

Confirmed, I have the same problem (cookies cleaned).

ksavenkov avatar Jan 19 '15 00:01 ksavenkov

For me, it is fixed after applying changes proposed in https://github.com/omab/python-social-auth/issues/445

ksavenkov avatar Jan 19 '15 01:01 ksavenkov

I've pushed the changes recommended in #445, could you give it a try?

omab avatar Jan 19 '15 14:01 omab

I was a little bit too optimistic. With this fix, the authorisation is successfully started, I got redirected to the twitter connect page, but after clicking "Sign In" I have 500 described in #487. If after experiencing that "Wrong state" error I repeat the auth attempt, then the backend gets an unauthorised token from cookies and that results in exactly the same behaviour described above.

ksavenkov avatar Jan 19 '15 18:01 ksavenkov

Seemingly, the problem is that session_get returns the following value in my case: "[u'oauth_token=uN14aAyXi42bqOHfs6ttlpTir7Gk6WBD&oauth_token_secret=KyO0jgFdUUboOPvTSP5ddTqi9wwEq3aA&oauth_callback_confirmed=true']". That is, insted of being a single-element array it's an string representation of the array, which has a type <type 'str'>, whilst [token] has type <type 'list'>.

ksavenkov avatar Jan 19 '15 18:01 ksavenkov

And the source of the problem is in session_set function: it receives value as a list of a single unicode string:

value = [u'foo']

and then sets the cookie as str(value), which is "[u'foo']".

When session_get is invoked, it reads the cookie as a string "[u'foo']", while expecting to receive a list ['foo'].

ksavenkov avatar Jan 19 '15 20:01 ksavenkov