Accounts.jsm

The Accounts object is only available to privileged code running on Firefox for Android, and is intended for use by Firefox for Android add-ons.

Mobile Only in Gecko 33
Available only in Firefox Mobile as of Gecko 33 (Firefox 33 / Thunderbird 33 / SeaMonkey 2.30)

Summary

The Accounts API lets you check if Firefox Account or a legacy Sync account is currently present on the device, and to start the Firefox Account set-up process if an account is not present. Accounts is a single object that provides a Promise-based API.

Method Overview

Promise anySyncAccountsExist()
Promise firefoxAccountsExist()
Promise syncAccountsExist()
void launchSetup(in object extras)

Methods

anySyncAccountsExist()

Query if either a Firefox Account or a legacy Sync account exists on the device.

Promise anySyncAccountsExist()
Return value

Returns a Promise that resolves to a boolean, true if either a Firefox Account or a legacy Sync account exists, false otherwise.

firefoxAccountsExist()

Query if a Firefox Account exists on the device.

Promise firefoxAccountsExist()
Return value

Returns a Promise that resolves to a boolean, true if a Firefox Account exists, false otherwise.

syncAccountsExist()

Query if a legacy Sync account exists on the device.

Promise syncAccountsExist()
Return value

Returns a Promise that resolves to a boolean, true if a legacy Sync account exists, false otherwise.

launchSetup(in object extras)

Launch the Firefox Account set-up wizard.

void syncAccountsExist(extras)
Parameters
extras
Extra options to pass to set-up wizard. Currently, extras can be used to specify custom Firefox Account and Sync token server URLs. See the examples for details.

Examples

To query for accounts and launch the set-up wizard if no account exists:

Components.utils.import("resource://gre/modules/Accounts.jsm");

Accounts.anySyncAccountsExist().then(
  (exist) => {
    console.log("Accounts exist? " + exist);
    if (!exist) {
      Accounts.launchSetup();
    }
  },
  (err) => {
    console.log("We failed so hard.");
  }
);

To launch the set-up wizard with custom Firefox Account and Sync token server URLs:

Components.utils.import("resource://gre/modules/Accounts.jsm");

// These server URLs are Mozilla's stage servers and are for testing only.
let customAuthServerURL = "https://api-accounts.stage.mozaws.net/v1";
let customSyncTokenServerURL = "https://token.stage.mozaws.net/1.0/sync/1.5";

let extras = {
    auth: customAuthServerURL,
    services: {
        sync: customSyncTokenServerURL,
    },
};

Accounts.launchSetup(extras);

See also

The fxa-custom-server-addon adds a menu item that prompts for custom server URLs and then starts the Account set-up wizard with those URLs.  It is available on Github:

Document Tags and Contributors

 Contributors to this page: wbamberg, nalexander
 Last updated by: wbamberg,