2011-06-10 8 views
5

私はoauthとopenidを別々に実装しています(つまりOpenIdでサインインし、Google Data APIとOAuthを別々に承認しています)それら。現在、私は私のapp.yamlにGoogle App Engineでpythonとopenid + oauthハイブリッドの良い例を探しています

- url: /_ah/login_required 
    script: main.py 

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

を以下している

はその後、main.pyに私が持っている: (明確にするため取り除か輸入)

def getClient(): 
    client = gdata.calendar.service.CalendarService() 
    consumer_key = 'my-app.appspot.com' 
    consumer_secret = 'consumersecret' 
    client.SetOAuthInputParameters(
     gdata.auth.OAuthSignatureMethod.HMAC_SHA1, 
     consumer_key=consumer_key, 
     consumer_secret=consumer_secret) 
    gdata.alt.appengine.run_on_appengine(client) 
    return client 

class OAuthOne(webapp.RequestHandler): 
    def get(self): 
     client = getClient() 
     request_token = client.FetchOAuthRequestToken(oauth_callback='http://my-app.appspot.com/oauth2') 
     client.SetOAuthToken(request_token) 
     auth_url = client.GenerateOAuthAuthorizationURL() 
     self.redirect(auth_url) 

class OAuthTwo(webapp.RequestHandler): 
    def get(self): 
     client = getClient() 
     token_from_url = gdata.auth.OAuthTokenFromUrl(self.request.uri) 
     if not token_from_url: 
      self.redirect('/oauth') 
     else: 
      client.SetOAuthToken(token_from_url) 
      oauth_verifier = self.request.get('oauth_verifier', default_value='') 
      client.UpgradeToOAuthAccessToken(oauth_verifier=oauth_verifier) 
      self.redirect('/') 

class MainPage(webapp.RequestHandler): 

    def get(self): 
     self.user = users.get_current_user() 
     self.template_values = {} 
     if self.user: 
      # do calendar api stuff here 
      self.template_file = 'templates/index.html' 
     else: 
      self.template_file = 'templates/denied.html' 

     path = os.path.join(os.path.dirname(__file__), self.template_file) 
     self.response.out.write(template.render(path, self.template_values)) 

application = webapp.WSGIApplication(
           [('/oauth', OAuthOne), 
            ('/oauth2', OAuthTwo), 
            ('/_ah/login_required', OpenIDHandler), 
            ('/', MainPage)], 
           debug=True) 

def main(): 
    run_wsgi_app(application) 

if __name__ == "__main__": 
    main() 

をもmain.pyで、 〜からhttp://code.google.com/googleapps/marketplace/tutorial_python_gae.html

class OpenIDHandler(webapp.RequestHandler): 
    def get(self): 
     """Begins the OpenID flow and begins Google Apps discovery for the supplied domain.""" 
     login_url = users.create_login_url(dest_url='http://my-app.appspot.com/', 
              _auth_domain=None, 
              federated_identity='gmail.com') 
     self.redirect(login_url) 

ハイブリッドプロトコルについては、PHP例hereとjavaの例hereですが、私はpythonのために何も見つけることができません。

私は、魔法の始まりが私のOpenIDHandlerで起こる必要があり、users.create_login_url()以外のものを使う必要があると私は考えます。 Googleのドキュメントhereでは、「検索を実行して認証要求を行うためのメカニズムを作成する」必要があることがわかります。と 'OAuth機能を認証リクエストに追加する'(その他のドキュメントhere)がありますが、その方法はわかりません。少なくともPythonではそうではありません。

あり少し低い生のHTTPリクエストの例はthis page

https://www.google.com/accounts/o8/id 
?openid.ns=http://specs.openid.net/auth/2.0 
&openid.claimed_id=http://specs.openid.net/auth/2.0/identifier_select 
&openid.identity=http://specs.openid.net/auth/2.0/identifier_select 
&openid.return_to=http://www.example.com/checkauth 
&openid.realm=http://www.example.com 
&openid.assoc_handle=ABSmpf6DNMw 
&openid.mode=checkid_setup 
&openid.ns.oauth=http://specs.openid.net/extensions/oauth/1.0 
&openid.oauth.consumer=www.example.com 
&openid.oauth.scope=http://docs.google.com/feeds/+http://spreadsheets.google.com/feeds/ 

上にあるしかし、私はこれを使用するかどうかはわかりません。

これがベストプラクティスの輝かしい例になるのを離れて、私は本当に「認証要求にOAuth機能を追加する」方法を知る必要があります。

+0

私は同じ問題を抱えています。私はハイブリッドプロトコルをPythonで使用したいと思いますが、例は見つかりませんでした。あなたはそれで管理しましたか?はいの場合は、コードの例を投稿してください。 –

答えて

関連する問題