JavaScript API

Normally, you simply include browserid/api.js and browserid/browserid.js on a page, and buttons generated by the template helpers will just work. If, however, you want more control, you can use the JavaScript API, defined in api.js directly.

For example, if you wanted to trigger login and show a message when there is an error:

$('.loginButton').click(function() {
    django_browserid.login().then(function(verifyResult) {
        window.location = verifyResult.redirect;
    }, function(jqXHR) {
        window.alert('There was an error logging in, please try again.');


See also browserid/browserid.js for an example of using the API.

This part of the documentation describes the JavaScript API defined in api.js.


Global object containing the JavaScript API for interacting with django-browserid.

Most functions return jQuery Deferreds for registering asynchronous callbacks.


Retrieve an assertion and use it to log the user into your site.


Deferred that resolves once the user has been logged in.


Log the user out of your site.

Returns:Deferred that resolves once the user has been logged out.

Retrieve an assertion via BrowserID.

Returns:Deferred that resolves with the assertion once it is retrieved.

Verify that the given assertion is valid, and log the user in.

  • assertion (string) – Assertion to verify.

Deferred that resolves with the login view response once login is complete.


Fetch information from the browserid_info tag, such as the parameters for the Persona popup.

Returns:Object containing the data from the info tag.

Fetch a CSRF token from the CsrfToken view via an AJAX request.

Returns:Deferred that resolves with the CSRF token.

Register callbacks with that make the API work. This must be called before calling any other API methods.

  • onReady (function) – Callback that will be executed after the user agent is ready to process login requests. This is passed as the onready argument to