Class: Session

Session

Manages the end user authentication session against (currently) pauth token.

This class is not intended to be used directly. You should instead use Client#login, Client#logout and Client's session property

See the Sequoia Documentation for more information.


new Session(transport, directory, registry, identityUri)

Parameters:
Name Type Argument Description
transport Transport

Transport instance to use for fetching

directory string

The directory (sometimes refered to as 'domain') that the user belongs to. This is prepended to the username on login requests (POSTs to /pauth/token)

registry Registry

a stored registry reference to query

identityUri string <nullable>

The endpoint URI for the sequoia identity service e.g. https://identity-sandbox.sequoia.piksel.com

Properties:
Name Type Argument Description
directory string

Stored from the initial directory parameter

identityUri string <nullable>

Stored from the initial identityUri parameter

token string <nullable>

The access_token returned from the call to /pauth/token after logging in

tenants Array.<Object>

Stored array of tenants the user has access to See the tenants documentation for more information.

access Object

Stored access information for the logged in user. See the access documentation for more information.

Source:
Example
import Session from '@pikselpalette/sequoia-js-client-sdk/lib/session';

const session = new Session('piksel', 'https://identity-sandbox.sequoia.piksel.com');
session.authenticateWithCredentials('username', 'password').then((session) => this.registry.fetch(session.currentOwner())).then(() => this.session)

Members


<nullable> currentTenant :string

The current tenant being used in this session.

When getting this propery, it will default to the first tenant in the Session.tenants array if this property has not been explicitly set

Will return null if there are no tenants available (e.g. the session is inactive)

Type:
  • string
Source:

Methods


authenticateWithCredentials(username, password, options)

Create a session based on end user credentials

Parameters:
Name Type Argument Description
username string <nullable>
password string <nullable>
options AuthenticationOptions <nullable>
Source:
See:
Returns:
Type
Promise

authenticateWithToken(token)

Create a session based on an existing bearer token

Use this if you acquire an access token via other means, i.e. an existing oauth mechanism for Sequoia

Parameters:
Name Type Description
token string
Source:
Returns:
Type
Promise

changePassword(oldPassword, newPassword)

Change the password of the user. Piksel Auth only.

Parameters:
Name Type Description
oldPassword string
newPassword string
Source:

clearExpiryWarning()

Clear the expiry warning callback and cancel any timers.

Source:

currentOwner()

Get the name (owner) of the current tenant

Source:
Returns:
Type
string

destroy()

Log out an end user

Source:
To Do:
  • Should this make a call to some service to revoke the auth token?
Returns:
Type
Session

findTenant()

Find a tenant by name in the current set of user available tenants

Source:
Returns:
Type
Object

isActive()

Returns whether there is a currently active logged in session

Source:
Returns:
Type
boolean

<private> populateAccess()

Populate the access properties of Session with data returned from Sequoia.

Source:
Returns:
Type
Promise

<private> populateTenants()

Populate the tenants properties of Session with data returned from Sequoia.

Source:
Returns:
Type
Promise

resetPassword(username)

Reset the password of the user. Piksel Auth only.

Parameters:
Name Type Description
username string
Source:

setDirectory(directory)

Set the directory after initialisation

Use this if you want to cache your client, but want to login under a different directory / domain

Parameters:
Name Type Description
directory string
Source:

setOnExpiryWarning(callback, threshold)

Set the expiry warning callback and threshold.

Parameters:
Name Type Argument Default Description
callback function <nullable>

Callback invoked when token is expiring

threshold Number <nullable>
60000

Threshold before expiry on which to invoke the callback, default 60000ms

Source:

startOnExpiryWarningTimer()

Start the expiry warning timer.

Source:

tokenExpiring(access)

Called when the token is about to expire. Calls the callback if registered.

Parameters:
Name Type Description
access AccessSession

The Sequoia access session

Source: