Identity
Extends:
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(options: Object): Error Authenticate user |
|
| public |
Clear the user data from localStorage |
|
| public |
crossAppPrompt(options: Object) 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 |
Current status of the IDM system |
|
| public |
Initialize SDK for use |
|
| public |
manageProfile(options: Object) ManageProfile user |
|
| public |
unauthenticate(options: Object): Promise<Identity, Error> Unauthenticate user |
|
Inherited Summary
| From class Observable | ||
| public |
Notify all observers of specified event type |
|
| public |
Register callback to be called with events of specified type |
|
Public Constructors
Public Members
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.
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:
| Name | Type | Attribute | Description |
| options | Object |
|
Options |
| options.properties | String[] |
|
Keys of specific user properties to request |
| options.origin | String |
|
Auth origin, e.g: NBC Login, Vote, BAT, ... |
| options.redirectUrl | String |
|
URL to redirect back to after authentication |
| options.token | String |
|
Identity token to (try to) use |
| options.facebookToken | String |
|
Facebook access token to (try to) use |
| options.marketingReferrer | String |
|
Referrer string based on show phase, e.g: S16_The Voice_BAT |
| options.propertyEdit | String |
|
Request that the passed properties be editable |
| options.enablePopUp | String |
|
Open authenticate in windowed pop-up instead of redirect. Overwrites initialize param |
| options.defaultPage | String |
|
Open authenticate to a specific page e.g: signUp, signupWithEmail, signIn |
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']
});
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
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); });
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:
| Name | Type | Attribute | Description |
| key | String | NBC App key, e.g: example |
|
| options | Object |
|
Options |
| options.debug | Boolean |
|
If true then enable logging |
| options.env | String |
|
Environment to use, e.g: dev/stage/acc/production |
| options.useLocalConfig | Boolean |
|
Flag that loads local config file if true |
| options.native | Boolean |
|
Enable native analytics bridge |
| options.token | String |
|
Identity user session token |
| options.topbar | String |
|
If false then the topbar is not displayed |
| options.useLocalConfig | Boolean |
|
Load config from local directory |
| options.enablePopUp | Boolean |
|
Open authenticate in windowed pop-up instead of redirect on all authenticate and unauthenticate calls |
| options.disableCookie | Boolean |
|
Disable the use of the standard cookie logic |
| options.configLocationHost | String |
|
Call config from custom host location |
public manageProfile(options: Object) source
ManageProfile user
Params:
| Name | Type | Attribute | Description |
| options | Object |
|
Options |
| options.properties | String[] |
|
Keys of specific user properties to request |
| options.marketingReferrer | String |
|
Referrer string based on show phase, e.g: S16_The Voice_BAT |
| options.propertyEdit | String |
|
Request that the passed properties be editable |
| options.defaultPage | String |
|
Open authenticate to a specific page e.g: signUp, signupWithEmail, signIn |
public unauthenticate(options: Object): Promise<Identity, Error> source
Unauthenticate user
Params:
| Name | Type | Attribute | Description |
| options | Object |
|
Options |
| options.origin | String |
|
Auth origin, e.g: NBC Login, Vote, BAT, ... |
| options.redirectUrl | String |
|
URL to redirect back to after authentication |
| options.token | String |
|
Identity token to (try to) use |
| options.redirect | Boolean |
|
Flag to redirect user to the auth app on unauthenticate |
| options.enablePopUp | String |
|
Open authenticate in windowed pop-up instead of redirect. Overwrites initialize param |
Manual
Reference
Source
Test
