Basic Authentication in Pylons

I had to create basic authentication in my project(based on Pylons), and this is simple solution to do it.

First, you have to open your config/middleware.py. It’s necessary to import AuthBasicHandler: from paste.auth.basic import AuthBasicHandler.

Next step is find ‘app = PylonsApp()‘. Change this line to: ap = PylonsApp() and add after: app = AuthBasicHandler(ap, “My realm”, authfunc). Of course you need to create auth function, for example:

def authfunc(environ, username, password):
    if username == 'myusername' and password == 'mypassword':
        return True
    else:
        return False

Restart your application environment.

That’s it :)

Share and Enjoy:
  • Google Bookmarks
  • Twitter
  • BLIP - Bardzo Lubię Informować Przyjaciół
  • pinger.pl - Nie taki zwykły blog.
  • Facebook
  • del.icio.us
  • Digg
  • Wrzuć to na Flakera - powiadom swoich Znajomych
  • grono.net - internetowa społeczność przyjaciół
  • Netvibes
  • LinkedIn
  • Technorati
  • Dodaj niusa « OSnews.pl

0 comments ↓

There are no comments yet...Kick things off by filling out the form below.

Leave a Comment