Welcome, guest | Sign In | My Account | Store | Cart

Notice! PyPM is being replaced with the ActiveState Platform, which enhances PyPM’s build and deploy capabilities. Create your free Platform account to download ActivePython or customize Python with the packages you require and get automatic updates.

Download
ActivePython
INSTALL>
pypm install flask-browserid

How to install Flask-BrowserID

  1. Download and install ActivePython
  2. Open Command Prompt
  3. Type pypm install flask-browserid
 Python 2.7Python 3.2Python 3.3
Windows (32-bit)
Windows (64-bit)
Mac OS X (10.5+)
Linux (32-bit)
0.0.1
0.0.4Never BuiltWhy not?
0.0.1 Available View build log
Linux (64-bit)
0.0.4 Available View build log
0.0.1 Available View build log
Web
 
Author
License
MIT
Dependencies
Lastest release
version 0.0.4 on Jan 9th, 2014

# Flask-BrowserID

A Flask extension that provides integration with Mozilla's [BrowserID]() authentication system and Flask-Login. It exposes two routes, for login and logout, and a javascript authentication bundle that allows you to quickly create login and logout buttons.

# Installation

Install with pip:

pip install git+https://github.com/garbados/flask-browserid.git

# Quickstart

Flask-BrowserID requires that Flask-Login's LoginManager be configured and registered with the app first, like so:

from flask import Flask from flask.ext.login import LoginManager from flask.ext.browserid import BrowserID from my_stuff import get_user_by_id # finds a user by their id from other_stuff import get_user # finds a user based on BrowserID response

app = Flask(__name__)

login_manager = LoginManager() login_manager.user_loader(get_user_by_id) login_manager.init_app(app)

browser_id = BrowserID() browser_id.user_loader(get_user) browser_id.init_app(app)

Now the routes /api/login and /api/logout have been registered with your app. A javascript bundle, auth_script, has also been added to the top level of your request context, so you can access it in templates like so:

[Note: auth_script requires JQuery and Mozilla's include.js]

<html>
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> <script src="https://login.persona.org/include.js" type="text/javascript"></script> <script type="text/javascript">{{ auth_script|safe }}</script>

System Message: WARNING/2 (<string>, line 40)

Definition list ends without a blank line; unexpected unindent.

</head> <body>

System Message: ERROR/3 (<string>, line 42)

Unexpected indentation.
{% if current_user.is_authenticated() %}
<button id="browserid-logout">Logout</button>
{% else %}
<button id="browserid-login">Login</button>

System Message: WARNING/2 (<string>, line 46)

Definition list ends without a blank line; unexpected unindent.

{% endif %}

System Message: WARNING/2 (<string>, line 47)

Block quote ends without a blank line; unexpected unindent.

</body>

System Message: WARNING/2 (<string>, line 48)

Definition list ends without a blank line; unexpected unindent.

</html>

Thanks to auth_script, clicking the Login button on that page will attempt to log you in using BrowserID. If you're already logged in, then clicking Logout will log you out.

# Required Configuration

Flask-BrowserID requires a function that takes the data returned by BrowserID and uses it to find and return a user, which Flask-BrowserID then logs in using Flask-Login. If the function can't find a user, it can attempt to create a user using the data given. If a user could neither be found nor created, the function should return None. The data returned by BrowserID will look something like this if successful:

{
"status": "okay", "email": "lloyd@example.com", "audience": "https://mysite.com", "expires": 1308859352261, "issuer": "browserid.org"

System Message: WARNING/2 (<string>, line 62)

Definition list ends without a blank line; unexpected unindent.

}

Or this, if not:

{
"status": "failure", "reason": "no certificate provided"

System Message: WARNING/2 (<string>, line 69)

Definition list ends without a blank line; unexpected unindent.

}

BrowserID's response will have already been parsed from JSON into a dict by the time it reaches your user_loader function.

# Optional Configuration

You can set the URLs Flask-BrowserID uses for login and logout by setting the following in your application's configuration:

  • BROWSERID_LOGIN_URL: defaults to /api/login
  • BROWSERID_LOGOUT_URL: defaults to /api/logout

See [Flask Configuration Handling](http://flask.pocoo.org/docs/config/) for more on how to configure your application.

# Testing

Running python setup.py test will run the extension's automated test suite, but some tests can only be run (presently) by manually starting up the server and clicking around. To do so, from the extension's root directory, run python tests/__init__.py -i. The -i flag tells the test suite to skip normal testing and instead run the testing application with a test template so you can click around.

# Credits

Many thanks to [Flask-Mongoengine](https://github.com/MongoEngine/flask-mongoengine), who I based the structure of this extension on, and to [Flask-Login](https://flask-login.readthedocs.org/en/latest/), for generally being a pretty sweet extension.

Subscribe to package updates

Last updated Jan 9th, 2014

Download Stats

Last month:1

What does the lock icon mean?

Builds marked with a lock icon are only available via PyPM to users with a current ActivePython Business Edition subscription.

Need custom builds or support?

ActivePython Enterprise Edition guarantees priority access to technical support, indemnification, expert consulting and quality-assured language builds.

Plan on re-distributing ActivePython?

Get re-distribution rights and eliminate legal risks with ActivePython OEM Edition.