Funciones Avanzadas

This is an archived page. It's not actively maintained.

In all example code in this page, gotAssertion is the callback argument to

Persistent Login

The API takes a set of options as an optional parameter. By using two of these options, allowPersistent and silent, you can enable the user to stay logged into your web site until the certificate signed by their identity provider expires.


You use allowPersistent like this:, {allowPersistent: true});

This option causes a new checkbox to appear in the BrowserID dialog asking the user if they want to stay signed in. If the user checks the box to stay signed in, then the browser creates an assertion and passes it to gotAssertion as normal, but remembers the user selection.


You use silent like this:, {silent: true});"}

With this option the browser will not display any dialog to the user, but will call gotAssertion without any user intervention. If the user had checked the box to stay signed in, and the user's certificate has not yet expired, then the browser will silently generate a new assertion and pass it into gotAssertion. Otherwise, the browser will pass null into gotAssertion.

Supporting Persistent Login

First, on page load, call{silent: true}):

$(function() {\n, {silent: true});\n});

Next, inside gotAssertion, if the assertion is not null and validates, log the user in, otherwise call loggedOut():

function gotAssertion(assertion) {
  if (assertion !== null) {
    // Send assertion to the server for validation
    if (!validateAssertionOnServer(assertion) loggedOut();
    else loggedIn();
  else {

Finally, loggedOut() updates the page to indicate that the user is logged out. In particular, the page needs to display a "Sign In" button whose click handler will call{allowPersistent: true}):

$('#browserid' }}).click(function() {, {allowPersistent: true});
  return false;

Example Code

You can see a sample implementation of this at, whose source code is available on GitHub.

Requiring a Specific Email

BrowserID enables a user to have multiple identities, and choose which one to sign in with. If a user has multiple email addresses which can be verified using BrowserID, then when a web site calls, the user will be presented with all their addresses, and asked which one to use.

Sometimes, though, a web site knows which email the user needs to choose. For example, if Alice shares a photo with Bob using a BrowserID-enabled photo-sharing site, the web site needs to authenticate Bob against the exact email address Alice used to invite him. If Bob chooses the wrong email from multiple choices the invitation will fail.

In this situation the web site can require that the user use a particular email address by setting the requiredEmail option as an argument to For example:, {requiredEmail: \"\"});

Even if Bob has multiple email addresses, he'll only be presented with "". The web site's gotAssertion() function is guaranteed to be called with either an assertion for "", or with a null assertion.