django使用Google App助手登录 [英] django login with google app acoounts
问题描述
嗯,我认为这应该不是一个大问题.但是,由于我已经花了超过一天的时间,所以我认为是时候寻求帮助了.
Well, I thought this shouldn't be a big problem. However, since I have spent more than one day on this, I think it is the time for asking help.
我有一个简单的django管理项目,现在可以正常工作.问题是我想实现仅允许用户使用特定的Google应用程序域(例如@ example.com)登录我的管理站点的功能.这样,用户不必手动创建帐户,我可以轻松地管理用户.
I have a simple django admin project and it works fine now. The problem is that I want to implement the feature that only allow the user login my admin site with particular google app domain, like @example.com. Then users doesn't have to manually create account and it is easy for me to manage users.
我相信这是许多网站都需要的通用功能.因此,我进行了一些搜索,发现一些帖子介绍了一些有趣的库.
I believe this is a common feature required by many websites. So I do some search and I found some posts introduce some interesting libraries.
这里的帖子很有帮助:
哪个openid/将django项目连接到Google Apps帐户的oauth库?
我认为应该为我工作的最后一个,但是没有.
The last one the one I think should work for me, but it doesn't.
我已经在github上安装了adieu的python-openid补丁: https://github.com/adieu/python-openid 并仍然显示相同的错误:"OpenID身份验证失败:身份URL主机的HTTP响应状态不是200.状态为404"
I have installed the python-openid patch from adieu on github:https://github.com/adieu/python-openid and it still give the same error: 'OpenID authentication failed: HTTP Response status from identity URL host is not 200. Got status 404'
经过一番挖掘,我无法找出解决方案.
After some diggings, I cannot figure out the solution.
然后,我开始寻找"Google帐户身份验证和授权",看看我是否可以自己构建整个系统.
Then I start looking for 'Google Accounts Authentication and Authorization' see if I can build the whole thing by myself.
现在,我的问题是,我应该继续使用现有的django库,还是应该从头开始做一些事情.
Now, my question, should I keep sticking on the exist django libraries or should I starts doing something from the beginnings.
因此,理想的解决方案要么是解决python-openid错误的提示,要么是提供下一步行动的方向(新库或Google帐户身份验证和授权)
So the ideal solution is either some hint for solving the error on python-openid or give the direction for next move (new libraries or Google Accounts Authentication and Authorization)
提前谢谢!
推荐答案
根据我的经验,您可以使用的最好的方法是 python-social-auth . Python社交身份验证使用其自己的结构来生成用户,但是您可以定义管道并说python-social-auth创建新用户,也可以创建 Django用户.
Based on my experience, best thing you can use is python-social-auth. Python social auth generates user with its own structure but you can define pipeline and say that whenever python-social-auth creates new user, you can also create django user.
这篇关于django使用Google App助手登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!