python - Multiple authentication options with Tornado -


just started playing tornado , want offer multiple methods of authentication. app working fine google's hybrid openid/oauth using tornado.auth.googlemixin , unauthenticated users automatically sent google's auth page.

if unauthenticated user wants use option (ie. local auth or tornado.auth.twittermixin), how can implement logic choose auth mechanism within login handler?

i added decorator 'tornado.web.authenticated' of exposed methods, , here login handler class (pretty straight tornado examples) working google openid/oauth:

class authloginhandler(basehandler, tornado.auth.googlemixin):     @tornado.web.asynchronous     def get(self):          if self.get_argument('openid.mode', none):             self.get_authenticated_user(self.async_callback(self._on_auth))             return          ## redirect after auth         self.authenticate_redirect()      def _on_auth(self, user):         ## auth fail         if not user:             raise tornado.web.httperror(500, 'google auth failed')          ## auth success         identity = self.get_argument('openid.identity', none)          ## set identity in cookie         self.set_secure_cookie('identity', tornado.escape.json_encode(identity))         self.redirect('/') 

appreciate suggestions solution. thanks

i think easiest way change authloginhandler more specific, googleauthhandler, , create appropriate route that:

(r"/login/google/", googleauthhandler), (r"/login/facebook/", facebookauthhandler), 

etc.

then create links each authentication provider on page ala:

<a href="/login/google/>login google</a> <a href="/login/facebook/">login facebook</a> 

if wanted make fancier, provide providers select box, or if wanted fancy, parse 'openid' url (e.g., if username.google.com, self.redirect("/login/google"), assumes users know openid provider urls, not case. i'd guess if gave them google / facebook / twitter icon or click on confuse least number of people.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -