Note that there are some explanatory texts on larger screens.

plurals
  1. POlooking for good example/template for openid + oauth hybrid with python in Google App Engine
    primarykey
    data
    text
    <p>I have implemented oauth and openid separately (that is, sign in with OpenId, separate authorization to Google Data API with OAuth) and would like to combine them. </p> <p>Currently I have the following in my app.yaml</p> <pre><code>- url: /_ah/login_required script: main.py - url: .* script: main.py login: required </code></pre> <p>Then, in main.py I have: (imports removed for clarity)</p> <pre><code>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() </code></pre> <p>also in main.py, from <a href="http://code.google.com/googleapps/marketplace/tutorial_python_gae.html">http://code.google.com/googleapps/marketplace/tutorial_python_gae.html</a></p> <pre><code>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 ) </code></pre> <p>As for the hybrid protocol, there is a PHP example <a href="http://code.google.com/p/gdata-samples/source/browse/trunk/hybrid/index.php">here</a>, and a java example <a href="http://code.google.com/p/step2/">here</a> but I cannot find anything for python. </p> <p>I assume that the start of the magic will need to happen in my OpenIDHandler, and that I need to use something other than <code>users.create_login_url()</code>. Google's documentation <a href="http://code.google.com/apis/accounts/docs/OpenID.html#settingup">here</a> tells me that I need to 'Create the mechanism for performing discovery and making authentication requests.' and 'Add OAuth capability to authentication requests' (more docs <a href="http://code.google.com/apis/accounts/docs/OpenID.html#oauth">here</a> ), but as far as I can tell, not how to do it. At least not with Python.</p> <p>There is an example of a raw http request a little lower on <a href="http://code.google.com/apis/accounts/docs/OpenID.html">this page</a></p> <pre><code>https://www.google.com/accounts/o8/id ?openid.ns=http://specs.openid.net/auth/2.0 &amp;openid.claimed_id=http://specs.openid.net/auth/2.0/identifier_select &amp;openid.identity=http://specs.openid.net/auth/2.0/identifier_select &amp;openid.return_to=http://www.example.com/checkauth &amp;openid.realm=http://www.example.com &amp;openid.assoc_handle=ABSmpf6DNMw &amp;openid.mode=checkid_setup &amp;openid.ns.oauth=http://specs.openid.net/extensions/oauth/1.0 &amp;openid.oauth.consumer=www.example.com &amp;openid.oauth.scope=http://docs.google.com/feeds/+http://spreadsheets.google.com/feeds/ </code></pre> <p>But I'm not sure how to use this.</p> <p>So apart from helping this become a shining example of a best practice, I really need to know how to 'Add OAuth capability to authentication requests'.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload