Manual Reference Source Test
import Identity from 'src/modules/identity.js'
public class | source

Identity

Extends:

Observable → Identity

NBC Identity SDK class

Note: The default export of this SDK is an instance of this class which is globally exposed as 'Identity' in the browser.

Constructor Summary

Public Constructor
public

Identity constructor

Member Summary

Public Members
public get

Additional Information bypass state

public get

Identity SDK state message

public get

Authenticate result

public get

Identity SDK state

public get

Current Identity user session token, or null

public get

Current authenticated Identity user, or null (read-only)

public get

Identity SDK version

Method Summary

Public Methods
public

Authenticate user

public

Clear the user data from localStorage

public

Initialize the native bridge to check for cross application credentials When credentials exist, redirect to the authenticate app to ask the user to sign in using those saved credentials When credentials don't exist, update state and do nothing

public

getHealth(env: String, timeout: number): Promise<Status, Error>

Current status of the IDM system

public

Initialize SDK for use

public

manageProfile(options: Object)

ManageProfile user

public

Unauthenticate user

Inherited Summary

From class Observable
public

notify(type: string, data: *)

Notify all observers of specified event type

public

on(type: string, callback: Function): Function

Register callback to be called with events of specified type

Public Constructors

public constructor() source

Identity constructor

Override:

Observable#constructor

Public Members

public get additionalInformationDisabled: Boolean source

Additional Information bypass state

public get message: String source

Identity SDK state message

public get result: String source

Authenticate result

Can be one of:

  • null - No result
  • 'registered' - Registered as a new user
  • 'logged in' - Logged in as existing user
  • 'completed' - User profile has been completed
  • 'cancelled' - Authentication was cancelled by user
  • 'logged out' - Logged out user
  • 'logout cancelled' - Logout cancelled by user
  • 'cross app login cancelled' - Cross app login cancelled by user

public get state: String source

Identity SDK state

Can be one of:

  • 'uninitialized'
  • 'initializing'
  • 'unauthenticated'
  • 'authenticated'
  • 'unauthenticating'
  • 'unableToFetchUserData'
  • 'cross-app-unavailable'
  • 'pop-up-blocked'

Changes to this value will be published as 'state' events.

Test:

public get token: String source

Current Identity user session token, or null

Test:

public get user: IdentityUser source

Current authenticated Identity user, or null (read-only)

Test:

public get version: String source

Identity SDK version

Test:

Public Methods

public authenticate(options: Object): Error source

Authenticate user

This will redirect the web browser or view to https://id.nbc.com/sdk/authenticate/ where an attempt will be made to take all necessary steps to result in a user with the specified properties after being redirected back.

If no properties are specified then all properties that have "request: true" in the config will be requested. If the user had already previously submitted valid property values for all of those however, the additional properties screen will be skipped, to allow for quick re-authentication. If some, but not all of the values were previously submitted then those will shown besides the invalid ones.

If properties are specified in this call then only those specific properties will be requested. In that case, even if the user had already previously submitted valid property values they will be re-requested, allowing the user to either specify or review and change those values. Only properties defined by the App's IdentityConfig can be requested.

If an Identity or Facebook token is specified then the authentication page will attempt to use those.

After the Authenticate page redirects back and this App re-initializes Identity#result can be used to determine the authentication result.

Params:

NameTypeAttributeDescription
options Object
  • optional
  • default: {}

Options

options.properties String[]
  • optional

Keys of specific user properties to request

options.origin String
  • optional

Auth origin, e.g: NBC Login, Vote, BAT, ...

options.redirectUrl String
  • optional
  • default: location.href

URL to redirect back to after authentication

options.token String
  • optional
  • default: this.token

Identity token to (try to) use

options.facebookToken String
  • optional

Facebook access token to (try to) use

options.marketingReferrer String
  • optional

Referrer string based on show phase, e.g: S16_The Voice_BAT

options.propertyEdit String
  • optional

Request that the passed properties be editable

options.enablePopUp String
  • optional

Open authenticate in windowed pop-up instead of redirect. Overwrites initialize param

options.defaultPage String
  • optional

Open authenticate to a specific page e.g: signUp, signupWithEmail, signIn

Return:

Error

Example:

// Default authentication based on App IdentityConfig:
Identity.authenticate();

// Or alternatively (e.g: opt-in at a later time) request specific properties:
Identity.authenticate({
  properties: ['sponsorOptIn']
});

Test:

public clearUser() source

Clear the user data from localStorage

public crossAppPrompt(options: Object) source

Initialize the native bridge to check for cross application credentials When credentials exist, redirect to the authenticate app to ask the user to sign in using those saved credentials When credentials don't exist, update state and do nothing

Params:

NameTypeAttributeDescription
options Object
  • optional
  • default: {}
options.origin String
  • optional
options.redirectUrl String
  • optional
  • default: location.href

public getHealth(env: String, timeout: number): Promise<Status, Error> source

Current status of the IDM system

Example usage: Identity.getHealth('dev', 2000).then(status => { console.log(status); });

Params:

NameTypeAttributeDescription
env String

Environment to use, e.g: dev/stage/acc/production

timeout number

Timeout limit on call response

Return:

Promise<Status, Error>

Promise of IDM status boolean

public initialize(key: String, options: Object): Promise<Identity, Error> source

Initialize SDK for use

This will start by fetching the IdentityConfig based on the specified env.

If the token option is specified then that value will be used.

Else the URL fragment will be parsed for the token, result and hash values passed to this web app upon returning from authentication and the original URL fragment (hash) value will be restored.

If no token is specified then token and user will be restored from local storage, provided the data has not timed out according to the IdentityConfig#sessionTimeout and/or IdentityConfig#userTimeout.

If a token is available but no user data (e.g: upon authentication or user data cache timeout) then the user data will be fetched from the IDM server and persisted before resolving this promise.

After initialization the Identity properties (e.g: Identity#state, Identity#result, Identity#token and Identity#user) can be examined.

Params:

NameTypeAttributeDescription
key String

NBC App key, e.g: example

options Object
  • optional
  • default: {}

Options

options.debug Boolean
  • optional
  • default: false

If true then enable logging

options.env String
  • optional
  • default: 'production'

Environment to use, e.g: dev/stage/acc/production

options.useLocalConfig Boolean
  • optional
  • default: false

Flag that loads local config file if true

options.native Boolean
  • optional
  • default: false

Enable native analytics bridge

options.token String
  • optional
  • default: null

Identity user session token

options.topbar String
  • optional
  • default: true

If false then the topbar is not displayed

options.useLocalConfig Boolean
  • optional
  • default: false

Load config from local directory

options.enablePopUp Boolean
  • optional
  • default: false

Open authenticate in windowed pop-up instead of redirect on all authenticate and unauthenticate calls

options.disableCookie Boolean
  • optional
  • default: false

Disable the use of the standard cookie logic

options.configLocationHost String
  • optional

Call config from custom host location

Return:

Promise<Identity, Error>

Promise of initialized Identity

Test:

public manageProfile(options: Object) source

ManageProfile user

Params:

NameTypeAttributeDescription
options Object
  • optional
  • default: {}

Options

options.properties String[]
  • optional

Keys of specific user properties to request

options.marketingReferrer String
  • optional

Referrer string based on show phase, e.g: S16_The Voice_BAT

options.propertyEdit String
  • optional

Request that the passed properties be editable

options.defaultPage String
  • optional

Open authenticate to a specific page e.g: signUp, signupWithEmail, signIn

public unauthenticate(options: Object): Promise<Identity, Error> source

Unauthenticate user

Params:

NameTypeAttributeDescription
options Object
  • optional
  • default: {}

Options

options.origin String
  • optional

Auth origin, e.g: NBC Login, Vote, BAT, ...

options.redirectUrl String
  • optional
  • default: location.href

URL to redirect back to after authentication

options.token String
  • optional
  • default: this.token

Identity token to (try to) use

options.redirect Boolean
  • optional

Flag to redirect user to the auth app on unauthenticate

options.enablePopUp String
  • optional

Open authenticate in windowed pop-up instead of redirect. Overwrites initialize param

Return:

Promise<Identity, Error>

Promise of unauthenticated Identity