pyramid_persona let you quickly set up authentication using persona on your pyramid project. It aims at giving as much as possible with as little configuration as possible, while still letting you customize if you want. If you want to see some screenshots of the demo app, take a look at this blog post.
You can find it on pypi as pyramid_persona.
Very basic usage
First of all, include pyramid_persona. Add this in your project configuration
Then, we need two little lines in your config files : a secret used to sign cookies, and the audience, the hostname and port of your website (this is needed for security reasons):
persona.secret = This is some secret string persona.audience = http://localhost:6543
There, we're done. We now have a nice forbidden view with a persona login button.
Less basic usage
Then, you can add the button in your page. request.persona_button provides a login if the user is not logged in, and a logout button if they are.
A basic page might be (using mako)
<button id='signin'>login</button> <button id='signout'>logout</button>
What it does
Here is, in details, what including pyramid_persona does :
- it defines an authentication policy, an authorization policy, and a session factory (this is needed for csrf protection, and is why we need a secret). Defaults are SessionAuthenticationPolicy, ACLAuthorizationPolicy and UnencryptedCookieSessionFactoryConfig. You can override it if you prefer.
- it adds a persona_button request attribute containing html code for quickly putting a login button.
- it defines the /login and /logout views to handle the persona workflow.
- it defines a basic forbidden view with a login button.
You can override any policy or view defined by pyramid_persona by defining them the usual way.
pyramid_persona defines the following settings :
- A secret string used to sign cookies. Required only if you do not defined another session factory.
- The protocol, domain name, and port of your site, as defined in the persona documentation. Required.
- The login route name. Optional, default is 'login'.
- The login route path. Optional, default is '/login'.
- The logout route name. Optional, default is 'logout'.
- The logout route path. Optional, default is '/logout'.
Python 3 compatibility
Sadly, this library depends on pyBrowserID, which is not compatible with python 3. I'll look into it, and hopefully, it'll be an easy port.
This project is made by Georges Dubus (@georgesdubus). Bug reports and pull requests are welcome.