2013-01-31 26 views
0

我想限制使用OpenID将登录运行在Google App Engine上的python应用程序登录到特定Google Apps域的成员。如何限制OpenID登录GAE上的一个Google Apps域

根据线程How limit Google Federated Login to specific Apps domain? 这可以通过完成简单的替代产品的普通谷歌的OpenID URL autentication

https://www.google.com/accounts/o8/id

https://google.com/accounts/o8/site-xrds?hd=example.com

然而,这似乎并没有使用users.create_login_url工作( )用于Python的GAE。它引发了500个服务器错误,该错误未显示在谷歌应用程序引擎日志中(日志只显示重定向和来自logging.debug的“OpenID”)。

有没有人有任何建议如何解决这个问题?

的app.yaml

application: example 
version: 1 
runtime: python27 
api_version: 1 
threadsafe: yes 

handlers: 
- url: /_ah/login_required 
    script: main.app 

- url: .* 
    script: main.app 
    login: required 

main.py:

import webapp2, logging 
from google.appengine.api import users 

# Any google account, works like a charm 
#federated_identity='https://www.google.com/accounts/o8/id' 

# only accounts under spefific domain, does not work 
federated_identity='https://google.com/accounts/o8/site-xrds?hd=example.com' 

dest_url = 'http://example.appspot.com/' 

class Main(webapp2.RequestHandler): 
    def get(self): 
     logging.debug('Main') 
     user = users.get_current_user() 
     if user: 
      self.response.out.write('Hello %s<p>[<a href="%s">log out</a>]' % (user.email(), 
        users.create_logout_url(self.request.uri))) 
     else: 
      self.response.out.write('Not logged in') 

class OpenID(webapp2.RequestHandler): 
    def get(self): 
     logging.debug('OpenID') 
     login_url = users.create_login_url(dest_url=dest_url, 
      federated_identity=federated_identity) 
     self.redirect(login_url) 

app = webapp2.WSGIApplication([ 
    ('/_ah/login_required', OpenID), 
    ('/', Main) 
], debug=True) 

更新
塞巴斯蒂安表明,一个解决办法可能是URL编码的联合身份。我试图按照建议对整个网址进行网址编码,或者只使用问号。不幸的是这并没有改变任何东西 如在浏览器地址栏,或者如果写入日志重定向网址:

没有URL编码:
http://example.appspot.com/_ah/login_redir?claimid=https://google.com/accounts/o8/site-xrds?hd=example.com&continue=http://example.appspot.com/

使用URL编码:
http://example.appspot.com/_ah/login_redir?claimid=https%3A%2F%2Fgoogle.com%2Faccounts%2Fo8%2Fsite-xrds%3Fhd%3Dexample.com&continue=http://example.appspot.com/

回答

0

我觉得(我没有我自己测试过)认为这个问题是因为federated_identity没有被编码。尝试用%3F替换问号。同时请确保网址为

https://google.com/accounts/o8/site-xrds?hd=example.com 

有效。

我做的测试是去URL

http://testsk2012.appspot.com/_ah/login_redir?claimid=https://www.google.com/accounts/o8/site-xrds%3Fhd=somesite.com&continue=http://testsk2012.appspot.com/ 

,它成功了。

+0

谢谢,但将“?”与“%3F”没有区别。我已经证明了网址在浏览器中的作用,所以这看起来与GAE的内部工作有关。 –

+0

你试过两个网址吗?另外,你可以发布生成的登录网址的样子吗? –

+0

谢谢塞巴斯蒂安。查看上面更新的帖子。 –

相关问题