简体   繁体   English

Google应用登录django

[英]Google apps login in django

I'm developing a django app that integrates with google apps. 我正在开发一个与谷歌应用程序集成的django应用程序。 I'd like to let the users login with their google apps accounts (accounts in google hosted domains, not google accounts ) so they can access their docs, calendar, and whatnot. 我想让用户使用他们的谷歌应用帐户登录(谷歌托管域中的帐户而不是谷歌帐户 ),以便他们可以访问他们的文档,日历和诸如此类的东西。

In order to do it, I downloaded and started using django_openid_auth (and thus, python-openid). 为了做到这一点,我下载并开始使用django_openid_auth(因此,python-openid)。

First, to test it, I used this url in my settings: 首先,为了测试它,我在我的设置中使用了这个url:

OPENID_SSO_SERVER_URL = 'https://www.google.com/accounts/o8/id'

And with that I managed to redirect the user to the google accounts page to login and then to return to my own domain, with the authentication cycle described by the google folks successfuly completed. 有了这个,我设法将用户重定向到谷歌帐户页面登录,然后返回到我自己的域,谷歌人员描述的身份验证周期已成功完成。 However, to login to google accounts is of little use for me, as I'd like the users who have a google apps account in their hosted domain -but not a google account- to login with. 但是,登录谷歌帐户对我来说没有什么用处,因为我希望在托管域中拥有谷歌应用程序帐户的用户 - 但不是谷歌帐户 - 登录。 In order to do that, I read the google article on discovery " Discovering OpenID Endpoints for Hosted Domains", and changed the aforementioned setting to: 为了做到这一点,我阅读了关于发现“发现托管域的OpenID端点”的谷歌文章,并将上述设置更改为:

OPENID_SSO_SERVER_URL = 'https://www.google.com/accounts/o8/site-xrds?hd=<my-domain>.com'

-where, obviously, <my-domain> is my actual domain ;) - 显然, <my-domain>是我的实际域名;)

But the backend responded with the following message: 但是后端回复了以下消息:

OpenID authentication failed: HTTP Response status from identity URL host is not 200. Got status 404 OpenID身份验证失败:来自身份URL主机的HTTP响应状态不是200.获得状态404

Debugging a little, I managed to find out that the code in python-openid (version 2.2.4) is the one that is misinterpreting the response from google, but I'm quite at loss here. 稍微调试一下,我设法发现python-openid(2.2.4版)中的代码是误解谷歌响应的代码,但我在这里很茫然。

I have seen the authentication in my own domain work in socialwok.com and puffypoodles.com So I'm quite certain that the auth cycle for my google apps domain works, but somehow python-openid can't seem to complete it (though, and I reiterate, it works just fine with plain old google accounts). 我已经看到我自己的域中的身份验证工作在socialwok.com和puffypoodles.com所以我很确定我的谷歌应用程序域的auth循环工作,但不知何故python-openid似乎无法完成它(但是,而且我重申,它适用于普通的旧谷歌帐户)。

Should I try to fix python-openid, or is there another way to fix this? 我应该尝试修复python-openid,还是有其他方法来解决这个问题? Has anyone successfuly managed to login with google apps in a pure django app ( not in google app engine )? 有没有人成功地在纯django应用程序( 不是谷歌应用程序引擎 )中使用谷歌应用程序登录?

According to http://groups.google.com/group/google-federated-login-api/web/openid-discovery-for-hosted-domains , Google changed the way of IdP Discovery and user XRDS check a little bit to give Google Apps users openid in http://example.com/openid?id=108441225163454056756 kind of format without asking the users to build their own openid servers. 根据http://groups.google.com/group/google-federated-login-api/web/openid-discovery-for-hosted-domains,Google改变了IdP发现的方式,用户XRDS检查了一下Google Apps用户以http://example.com/openid?id=108441225163454056756格式开放,而无需要求用户构建自己的openid服务器。 For small companies, people can get their openid under their domain with as few as just a domain name if they use Google Apps. 对于小公司而言,如果他们使用Google Apps,人们就可以在他们的域名下使用少量域名。

This might be a good approach because people could use their Google Apps Account for the authentication, and they can still give out openids under their own domain which they could change the authentication backend for in the future. 这可能是一种很好的方法,因为人们可以使用他们的Google Apps帐户进行身份验证,他们仍然可以在自己的域下提供openid,以便将来更改身份验证后端。 It is simple and extendable, but sadly it hasn't became the standard yet. 它简单且可扩展,但遗憾的是它尚未成为标准。 So, if you use standard library like python-openid, you will encounter some problems. 所以,如果你使用像python-openid这样的标准库,你会遇到一些问题。

To solve those problems, you have to patch python-openid yourself to follow Google's approach. 要解决这些问题,你必须自己修补python-openid以遵循谷歌的方法。

I ran into the same problem before and I have a patched version of python-openid v2.1.1 which works for me. 之前我遇到过同样的问题,我有一个python-openid v2.1.1的补丁版本,对我有用。

If you need, I could post my code after some cleanup. 如果需要,我可以在清理后发布我的代码。 It was a quick patch, so don't expect too much :) 这是一个快速补丁,所以不要期望太多:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM