2013-01-31 30 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

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

相關問題