Skip to content

@ubstream/ubstream-node-client-sdk / Exports / SessionContext

Class: SessionContext

Table of contents

Properties

Accessors

Methods

Properties

additionalRequestHeaders

Readonly additionalRequestHeaders: Dict<string | string[]>

Additional headers for each request


apiUrl

Readonly apiUrl: string

The url of the API.

Accessors

accessToken

get accessToken(): undefined | string

Returns

undefined | string

Return the token or undefined if the token is not defined.

Summary

Get the access token.

Example

const token = await client.session.accessToken;

Methods

login

login(username, password): Promise<IUbstreamApiToken>

Parameters

Name Type Description
username string The username.
password string The password or apiKey.

Returns

Promise<IUbstreamApiToken>

Promise object representing all information concerning authentication.

Summary

Allows to login from the API.

Example

// Initialize the sdk with credentials
const client = new UbstreamClient({
     apiUrl: "https://developer.ubstream.com/api/v1"
});
// Login - creation of session. From this point you're authenticated. After be logged, the token is refreshed automatically.
await client.session.login("login", "password");

logout

logout(): Promise<void>

Returns

Promise<void>

Promise object

Summary

Allows to logout from the API.

Example

// Logout - Expiration of the refresh token. At this point, you will be logged out at the end of the current access token lifetime.
await client.session.logout("refreshToken");

refresh

refresh(refreshToken?): Promise<IUbstreamApiToken>

Parameters

Name Type Description
refreshToken? string The token to refresh. If not provided current token is used

Returns

Promise<IUbstreamApiToken>

Promise object representing all information concerning authentication.

Summary

Get the access token.

Example

const token = await client.session.refresh;

setAccessToken

setAccessToken(token): void

Parameters

Name Type Description
token string The new token.

Returns

void

Summary

Allows to set manually the token. After the modification, if you are logged, the token will be refreshed automatically with the information provided during login.

Example

await client.session.setAccessToken("new_token");