Perform a "client_credentials" authentication using the OAuth 2.0 server and registers it in current Session.
Destroy the Session and clears the storage.
Fetch the currently stored Session from local storage.
Get the Session interceptors for authorized calls and auto Session destruction.
Returns a promise to await fetching completion.
Perform a "password" authentication using the OAuth 2.0 server and registers it in current Session.
The User credentials.
Performs a "refresh_token" authentication using the OAuth 2.0 server and registers it in current session. This method is automatically called on requests that return 401
Register a new User in session, notifying all observers.
The User instance.
The operation options.
Reload the current User using the remote server.
Subscribe for updates.
The instace to be notified.
Unsubscribe from updates.
The instance to be removed from listeners.
Get the Session singleton instance.
Generated using TypeDoc
An abstraction layer to securely store and manage platform credentials.
The Session is a singleton, so you may access the authentication state at any time, in any context, getting its current instance. It is also an observable, so it can be watched for changes:
import { Observer } from 'bitcapital-core-sdk'; // Gets the current Session instance const session = bitcapital.session(); // Shows the current user instance, if any console.log(session.current); // Prepare a new session observer (typescript notation) const observer: Observer = { update(event: string, data: User) { if(event === Session.EVENT_SESSION_CHANGED) { console.log('User instance has changed in Session', { user: data }); } } }; // Start listening to Session changes, such as credentials // expiration or a refreshed access token. session.subscribe(observer); // ... // Eventually, you can also stop listening to its changes session.unsubscribe(observer);