AppID

AppID

This class provides functions to support authentication.

Constructor

new AppID()

Source:

This creates an instance of AppID. Once created, call init() before attempting to sign in.

Example
const appID = new AppID();

Methods

(async) init(options) → {Promise.<void>}

Source:

Initialize AppID. Call this function before attempting to sign in. You must wait for the promise to resolve.

Example
await appID.init({
	clientId: '<SPA_CLIENT_ID>',
	discoveryEndpoint: '<WELL_KNOWN_ENDPOINT>'
});
Parameters:
Name Type Description
options Object
Properties
Name Type Attributes Description
clientId string

The clientId from the singlepageapp application credentials.

discoveryEndpoint string

The discoveryEndpoint from the singlepageapp application credentials.

popup Object <optional>

The popup configuration.

Properties
Name Type Description
height Number

The popup height.

width Number

The popup width.

Throws:
  • For missing required params.

    Type
    AppIDError
  • Any errors during a HTTP request.

    Type
    RequestError
Returns:
Type
Promise.<void>

(async) signin() → {Promise.<Tokens>}

Source:

This will open a sign in widget in a popup which will prompt the user to enter their credentials.
After a successful sign in, the popup will close and tokens are returned.

Example
const {accessToken, accessTokenPayload, idToken, idTokenPayload} = await appID.signin();
Throws:
  • "Popup closed" - The user closed the popup before authentication was completed.

    Type
    PopupError
  • Any token validation error.

    Type
    TokenError
  • Any errors from the server according to the OAuth spec. e.g. {error: 'server_error', description: ''}

    Type
    OAuthError
  • Any errors during a HTTP request.

    Type
    RequestError
Returns:

The tokens of the authenticated user.

Type
Promise.<Tokens>

(async) silentSignin() → {Promise.<Tokens>}

Source:

Silent sign in allows you to automatically obtain new tokens for a user without the user having to re-authenticate using a popup.
This will attempt to authenticate the user in a hidden iframe.
You will need to enable Cloud Directory SSO.
Sign in will be successful only if the user has previously signed in using Cloud Directory and their session is not expired.

Example
const {accessToken, accessTokenPayload, idToken, idTokenPayload} = await appID.silentSignin();
Throws:
  • Any errors from the server according to the OAuth spec. e.g. {error: 'access_denied', description: 'User not signed in'}

    Type
    OAuthError
  • "Silent sign-in timed out" - The iframe will close after 5 seconds if authentication could not be completed.

    Type
    IFrameError
  • Any token validation error.

    Type
    TokenError
  • Any errors during a HTTP request.

    Type
    RequestError
Returns:

The tokens of the authenticated user.

Type
Promise.<Tokens>

(async) getUserInfo(accessToken) → {Promise}

Source:

This method will make a GET request to the user info endpoint using the access token of the authenticated user.

Parameters:
Name Type Description
accessToken string

The App ID access token of the user.

Throws:
  • "Access token must be a string" Invalid access token.

    Type
    AppIDError
  • Any errors during a HTTP request.

    Type
    RequestError
Returns:

The user information for the authenticated user. Example: {sub: '', email: ''}

Type
Promise

(async) changePassword(idToken) → {Promise.<Tokens>}

Source:

This method will open a popup to the change password widget for Cloud Directory users.
You must enable users to manage their account from your app in Cloud Directory settings.

Example
let tokens = await appID.changePassword(idToken);
Parameters:
Name Type Description
idToken string

A JWT.

Throws:
  • "Expect id token payload object to have identities field"

    Type
    AppIDError
  • "Must be a Cloud Directory user"

    Type
    AppIDError
  • "Missing id token string"

    Type
    AppIDError
Returns:

The tokens of the authenticated user.

Type
Promise.<Tokens>

(async) changeDetails(tokens) → {Promise.<Tokens>}

Source:

This method will open a popup to the change details widget for Cloud Directory users.
You must enable users to manage their account from your app in Cloud Directory settings.

Example
let tokens = {accessToken, idToken}
let newTokens = await appID.changeDetails(tokens);
Parameters:
Name Type Description
tokens Object

App ID tokens

Throws:
  • "Missing id token string"

    Type
    AppIDError
  • "Missing access token string"

    Type
    AppIDError
  • "Missing tokens object"

    Type
    AppIDError
Returns:
Type
Promise.<Tokens>