FxAccountsOAuthClient.jsm

The FxAccountsOAuthClient.jsm JavaScript module provides a way for browser services to authenticate with the Firefox Accounts OAuth server.

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

Creating a new FxAccountsOAuthClient

new FxAccountsOAuthClient(Object options);

Method overview

launchWebFlow();
tearDown();

Attributes

parameters Object Returns the set of parameters that initialized the Firefox Accounts OAuth flow.
onComplete Function Gets called when the Firefox Accounts OAuth flow successfully completes. First and only argument is an Object that has "state" and "code" properties. 

Constructor FxAccountsOAuthClient()

Creates and returns a new FxAccountsOAuthClient object.

FxAccountsOAuthClient FxAccountsOAuthClient(
  Object options
    Object parameters
      String client_id
      String state
      String oauth_uri
      String content_uri
      [optional] String scope
      [optional] String action
    [optional] String authorizationEndpoint
); 
Parameters
  • client_id - OAuth id returned from client registration.
  • state - OAuth state value that will be returned to the client as-is upon redirection.
  • oauth_uri - The FxA OAuth API server uri, versioned. Example: "https://oauth.accounts.firefox.com/v1"
  • content_uri - The FxA Content server uri. Example: "https://accounts.firefox.com"
  • [optional] scope - A colon-separated list of scopes that the user has authorized.
  • [optional] action - If provided, should be either "signup" or "signin".
parameters
Set of parameters to initialize the Firefox Accounts OAuth flow.
authorizationEndpoint Optional
Optional authorization endpoint for the OAuth server. Default: /authorization
Return value

A newly created FxAccountsOAuthClient object implementing the methods described in this article.

Methods

launchWebFlow()

Opens a new tab at the Firefox Accounts OAuth authorization URL. Registers a WebChannel listener and sets up a callback if needed.
Parameters
None

tearDown()

Call this function to manually release all channels and callbacks that are in use by this client.
Parameters
None

Examples

Using the FxAccountsOAuthClient

Chrome code

let parameters = {
  oauth_uri: OAUTH_SERVER_ENDPOINT, 
  client_id: OAUTH_CLIENT_ID,
  content_uri: CONTENT_SERVER_URL,
  state: OAUTH_STATE
}
let client = new FxAccountsOAuthClient({
  parameters: parameters
});
client.onComplete =  function (tokenData) {
  // tokenData consists of two properties: "tokenData.state" and "tokenData.code"
};
client.launchWebFlow();

See also

Document Tags and Contributors

 Last updated by: vladikoff,