Home Reference Source Test Repository
import DeviceCode from '@npr/npr-one-sdk/model/device-code.js'
public class | source

DeviceCode

A thin wrapper around the raw JSON returned from the authorization server to represent a device code/user code pair

Test:

Constructor Summary

Public Constructor
public

Member Summary

Public Members
public get

Returns the interval (in milliseconds) at which the client (in this case the SDK) should poll the POST /token endpoint (or the OAuth proxy that lies in between).

public get

Returns the TTL (in milliseconds) until this device code/user code pair expires.

public get

Returns the user code (8-character alphanumeric string)

public get

Returns the verification URL (the place where the user should go on their mobile device or laptop to log in)

Method Summary

Public Methods
public

Returns whether or not this device code/user code pair has expired.

public

A convenience function to cast this object back to a string, generally only used by the Logger class.

public

Ensure that the given device code model is valid

Public Constructors

public constructor(json: Object) source

Params:

NameTypeAttributeDescription
json Object

The decoded JSON object that should be used as the basis for this model

Test:

Public Members

public get interval: number source

Returns the interval (in milliseconds) at which the client (in this case the SDK) should poll the POST /token endpoint (or the OAuth proxy that lies in between). Consumers of the SDK should generally not have to use this value directly.

Test:

public get ttl: number source

Returns the TTL (in milliseconds) until this device code/user code pair expires. The SDK will automatically generate a new key pair upon expiry, so consumers of the SDK will generally not have to use this value directly; however, you may opt to display on the screen how much time the user has left to log in before a new code is generated.

Test:

public get userCode: string source

Returns the user code (8-character alphanumeric string)

Test:

public get verificationUri: string source

Returns the verification URL (the place where the user should go on their mobile device or laptop to log in)

Test:

Public Methods

public isExpired(): boolean source

Returns whether or not this device code/user code pair has expired. Note that due to network latency, etc., it's possible that the internally-stored expiry date could be about a second or so behind, and so this function is not guaranteed to be perfectly accurate.

Return:

boolean

Test:

public toString(): string source

A convenience function to cast this object back to a string, generally only used by the Logger class. In this case, we return the raw JSON string representing the entire object.

Return:

string

Test:

public validate() source

Ensure that the given device code model is valid

Throw:

TypeError

if device code model is invalid

Test: