django REST facebook认证 [英] django REST facebook authentication

查看:194
本文介绍了django REST facebook认证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个允许使用django-social-auth进行Facebook身份验证的网站

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

现在我还需要使用非基于cookie的API进行身份验证。我的想法是将sessionid =作为POST字段(它将使用HTTPS)。到目前为止,我设法愚弄django来访问这个sessionid,就像它是一个cookie一样(我基本上在中间件中做一些请求.COOKIES ['sessionid'] = request.POST ['sessionid']。

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).

我的问题是如何在认证后给予用户sessionid。
从我可以发现,Facebook给用户一个访问令牌,然后发送到/ complete / facebook /,由django-social-auth处理,并返回一个Set-cookie头,其中包含sessionid键。但是,而不是这样,我需要它将sessionid键作为页面内容中的json返回(API客户端不能读取http响应头)。

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).

推荐答案

似乎是一个挑战。但是也许你可以利用一个保存信号来触发所需的JSON的Comet事件。作为起点,旧版本的django-social-auth文档似乎提到了信号。

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

然而,一个更好的方法可能是跳过django-social-auth在一起,去一个python社会认证。文档本身说:
注意:这个图书馆在python-social-auth中被拒绝。

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."

这篇关于django REST facebook认证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆