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.');
});
});
Note
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
.
-
django_browserid
¶ Global object containing the JavaScript API for interacting with django-browserid.
Most functions return jQuery Deferreds for registering asynchronous callbacks.
-
login
([requestArgs])¶ Retrieve an assertion and use it to log the user into your site.
Arguments: - requestArgs (object) – Options to pass to navigator.id.request.
Returns: Deferred that resolves once the user has been logged in.
-
logout
()¶ Log the user out of your site.
Returns: Deferred that resolves once the user has been logged out.
-
getAssertion
([requestArgs])¶ Retrieve an assertion via BrowserID.
Returns: Deferred that resolves with the assertion once it is retrieved.
-
verifyAssertion
(assertion)¶ Verify that the given assertion is valid, and log the user in.
Arguments: - assertion (string) – Assertion to verify.
Returns: Deferred that resolves with the login view response once login is complete.
-
getInfo
()¶ Fetch information from the
browserid_info
tag, such as the parameters for the Persona popup.Returns: Object containing the data from the info tag.
-
getCsrfToken
()¶ Fetch a CSRF token from the
CsrfToken view
via an AJAX request.Returns: Deferred that resolves with the CSRF token.
-
registerWatchHandlers
([onReady])¶ Register callbacks with navigator.id.watch that make the API work. This must be called before calling any other API methods.
Arguments: - 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 navigator.id.watch
- onReady (function) – Callback that will be executed after the user
agent is ready to process login requests. This is passed as the
-