django REST facebook authentication

雨燕双飞 提交于 2020-01-02 03:48:24

问题


I have a site that allows Facebook authentication using django-social-auth

Now I also need to authenticate using a non-cookie-based API. My idea is to include a "sessionid=" as a POST field (it will be using HTTPS). So far I managed to "fool" django to access this sessionid as if it were a cookie (I basically do something like request.COOKIES['sessionid'] = request.POST['sessionid'] in a middleware).

My problem is how to give the sessionid to the user right after he authenticated. From what I could find out, facebook gives the user an "access token" which is then sent to /complete/facebook/ , which is processed by django-social-auth and returns a "Set-cookie" header containing the "sessionid" key. But instead of that, I'd need it to return the sessionid key as a json in the page content (the API client can't read http response header).


回答1:


Seems like a challenge. But perhaps you can make use of a save signal that fires a Comet event with the required JSON. As a starting point an old version of the django-social-auth doc seems to mention signals.

https://django-social-auth.readthedocs.org/en/v0.7.1/signals.html

However a better approach may be to skip django-social-auth all together and go for a python social auth. The documentation itselfs says: "NOTE: THIS LIBRARY IS DEPRECATED IN FAVOR OF python-social-auth."



来源:https://stackoverflow.com/questions/9467292/django-rest-facebook-authentication

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!