Initialize and Authenticate
Workflow Guide
This guide describes the operations related to initializing the b.well SDK and authenticating users. Before accessing any health data or SDK functionality, you must first initialize the SDK with your client credentials and establish user authentication. The SDK supports multiple authentication methods to accommodate different implementation scenarios.
Prerequisites
- Valid clientKey must be provided in the constructor
- Network connectivity to b.well services
Summary of Steps
- Initialize the b.well SDK with client credentials using initialize
- Authenticate the user with one of the following methods: authenticate, setAuthenticationTokens, authenticateFromStorage
Step 1: Initialize the b.well SDK
Use the initialize method to configure the SDK with your client credentials and environment settings before any other SDK methods can be used.
Example Request:
import { BWellSDK } from '@bwell/sdk';
const sdk = new BWellSDK({ clientKey: "YOUR_CLIENT_KEY" });
await sdk.initialize();Step 2: Authenticate the User
Use the appropriate authentication method based on your implementation strategy to validate user credentials.
Standard Authentication
Use the authenticate method when you have user credentials (e.g. access token, username and password). This method authenticates a user with provided credentials and establishes token management preparing the SDK for making authorized requests.
Example Request:
await sdk.authenticate({
token: 'your-access-token',
});Set Pre-obtained Authentication Tokens
Use the setAuthTokens method when authentication tokens have been obtained through external means (e.g., SSO, external identity provider). This method performs token validation and can be used in place of authenticate for a pre-authenticated user.
Example Request:
await sdk.setAuthenticationTokens({
accessToken: 'your-access-token',
refreshToken: 'your-refresh-token',
idToken: 'your-id-token'
});Authenticate from Stored Tokens
Use the authenticateFromStorage method to restore a user session by authenticating with previously stored tokens from the configured storage. This eliminates the need for manual credential re-entry and provides a seamless user experience across sessions.
Example Request:
await sdk.authenticateFromStorage();Note: This method requires that tokens were previously stored during an earlier authentication session and that the configured storage mechanism is accessible.
For complete request and response schema, see Bwell TypeScript SDK documentation.
Updated about 2 months ago
