OAuthAuthenticator

auth. OAuthAuthenticator

Abstracts the sign-in, sign-up and change-password processes for Database & Active Directory authentication services.

Constructor

new OAuthAuthenticator(options)

Source:
Parameters:
Name Type Description
options Object

Authenticator options.

Name Type Attributes Description
baseUrl String

The Auth0 account URL.

domain String

AuthenticationClient server domain

clientId String <optional>

Default client ID.

clientSecret String <optional>

Default client Secret.

__bypassIdTokenValidation Boolean <optional>

Whether the id_token should be validated or not

Members

(inner) clientOptions :Object

Options object for the Rest Client instace.

Source:
Type:
  • Object

Methods

authorizationCodeGrant(data) → {Promise|undefined}

Sign in using an authorization code

Source:
Parameters:
Name Type Description
data Object

Authorization code payload

userData.code String

Code in URL returned after authentication

userData.redirect_uri String

The URL to which Auth0 will redirect the browser after authorization has been granted by the user.

Returns:
Type:
Promise | undefined
Example

Given the code returned in the URL params after the redirect from successful authentication, exchange the code for auth0 credentials. It will return JSON with the access_token and id_token. More information in the API Docs .

var data = {
  code: '{CODE}',
  redirect_uri: '{REDIRECT_URI}',
  client_id: '{CLIENT_ID}',  // Optional field.
  client_secret: '{CLIENT_SECRET}',  // Optional field.
};

auth0.oauth.authorizationCodeGrant(data, function (err, userData) {
  if (err) {
    // Handle error.
  }

  console.log(userData);
});

passwordGrant(userData, optionsopt) → {Promise|undefined}

Sign in using a username and password

Source:
Parameters:
Name Type Attributes Description
userData Object

User credentials object.

Name Type Attributes Description
username String

Username.

password String

User password.

realm String <optional>

Name of the realm to use to authenticate or the connection name

options Object <optional>

Additional options.

Name Type Attributes Description
forwardedFor String <optional>

Value to be used for auth0-forwarded-for header

Returns:
Type:
Promise | undefined
Example

Given the user's credentials perform the OAuth password grant or Password Realm grant if a realm is provided, it will return a JSON with the access_token and id_token. More information in the API Docs .

var data = {
  client_id: '{CLIENT_ID}',  // Optional field.
  username: '{USERNAME}',
  password: '{PASSWORD}',
  realm: '{CONNECTION_NAME}', // Optional field.
  scope: 'openid'  // Optional field.
};

auth0.oauth.passwordGrant(data, function (err, userData) {
  if (err) {
    // Handle error.
  }

  console.log(userData);
});

refreshToken(data) → {Promise|undefined}

Exchange a refresh token

Source:
Parameters:
Name Type Description
data Object

Data object.

Name Type Description
refresh_token String

Refresh token.

Returns:
Type:
Promise | undefined
Example

Given a refresh token from a previous authentication request it will return a JSON with the access_token and id_token if the openid scope was originally included. More information in the API Docs .

var data = {
  refresh_token: '{REFRESH_TOKEN}',
};

auth0.oauth.refreshToken(data, function (err, data) {
  if (err) {
    // Handle error.
  }

  console.log(data);
});

signIn(userData, optionsopt) → {Promise|undefined}

Sign in using a username and password.

Source:
Parameters:
Name Type Attributes Description
userData Object

User credentials object.

Name Type Description
username String

Username.

password String

User password.

connection String

The identity provider in use.

options Object <optional>

Additional options.

Name Type Attributes Description
forwardedFor String <optional>

Value to be used for auth0-forwarded-for header

Returns:
Type:
Promise | undefined
Example

Given the user's credentials and the connection specified, it will return a JSON with the access_token and id_token. More information in the API Docs .

var data = {
  client_id: '{CLIENT_ID}',  // Optional field.
  username: '{USERNAME}',
  password: '{PASSWORD}',
  connection: '{CONNECTION_NAME}',
  scope: 'openid'  // Optional field.
};

auth0.oauth.signIn(data, function (err, userData) {
  if (err) {
    // Handle error.
  }

  console.log(userData);
});

socialSignIn(data) → {Promise|undefined}

Sign in using a social provider access token.

Source:
Parameters:
Name Type Description
data Object

User credentials object.

Name Type Description
access_token String

User access token.

connection String

Identity provider.

Returns:
Type:
Promise | undefined