2011-06-10 22 views
5

में पायथन के साथ ओपनिड + ओथ हाइब्रिड के लिए अच्छा उदाहरण/टेम्पलेट ढूंढना मैंने ओथ और ओपनिड को अलग से लागू किया है (यानी ओपनआईडी के साथ साइन इन करें, ओएथ के साथ Google डेटा एपीआई के लिए अलग प्रमाणीकरण) और गठबंधन करना चाहते हैं उन्हें।Google ऐप इंजन

वर्तमान में मैं अपने app.yaml में निम्नलिखित है

- 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, और जावा उदाहरण here लेकिन मुझे अजगर के लिए कुछ भी नहीं मिला।

मुझे लगता है कि जादू की शुरुआत मेरे ओपनआईडहैंडलर में होने की आवश्यकता होगी, और मुझे users.create_login_url() के अलावा कुछ और उपयोग करने की आवश्यकता है। Google के दस्तावेज़ here मुझे बताता है कि मुझे 'खोज करने और प्रमाणीकरण अनुरोध करने के लिए तंत्र बनाना' की आवश्यकता है। और 'प्रमाणीकरण अनुरोधों के लिए OAuth क्षमता जोड़ें' (अधिक दस्तावेज़ here), लेकिन जहां तक ​​मैं कह सकता हूं, यह कैसे करें। कम से कम पायथन के साथ नहीं।

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/ 

पर एक कच्चे http अनुरोध एक छोटे से कम का एक उदाहरण नहीं है लेकिन मैं यह कैसे उपयोग करने के लिए यकीन नहीं है।

तो यह एक सर्वोत्तम अभ्यास का चमकदार उदाहरण बनने में मदद करने के अलावा, मुझे वास्तव में यह जानने की आवश्यकता है कि 'प्रमाणीकरण अनुरोधों के लिए ओथ क्षमता कैसे जोड़ें'।

+0

मुझे एक ही समस्या है, मैं पाइथन में हाइब्रिड प्रोटोकॉल का उपयोग करना चाहता हूं लेकिन मुझे कोई उदाहरण नहीं मिला है। क्या आपने इसके साथ काम किया? यदि हां, तो कृपया कोड का उदाहरण पोस्ट करें। –

उत्तर