Authentication
AWS Cognito JWT Authentication
Section titled “AWS Cognito JWT Authentication”API requests require an authentication header with a JWT token received from the AWS Cognito service. You will need a user login and password to send such a request. We recommend using the AWS SDK library as a handy helper. List of official AWS SDK in multiple programming languages
We have prepared example code which shows the authorization flow written in Node.js. For the full working sample project, see the Unleash Live API Samples GitHub repository.
Prerequisites: Node.js v18 or later. Install dependencies with
npm installunder thejavascript/directory.
Configuration
Section titled “Configuration”Environment variables and Cognito pool settings are defined in env.js.
User credentials are defined in user.js — replace the placeholder values with your own login email and password (the same credentials used to log in to cloud.unleashlive.com).
Cognito Helpers
Section titled “Cognito Helpers”The cognito.js module provides helper functions for:
- Initialising the AWS SDK client with identity pool credentials
- Creating a Cognito user pool and user instances
- Decoding JWT tokens
- Building authentication details
Sign-In Flow
Section titled “Sign-In Flow”The actions.js module uses the Cognito helpers to authenticate a user. On success it returns the access token, ID token, refresh token, and custom claims (identityId, companyId, teamId).
An example sign-in script can be run from any of the sample entry points (e.g. media-drive, flights).
Required Headers
Section titled “Required Headers”Every GraphQL request must include the header authorization with the ID token.
Every REST request must include the header X-Amz-Cognito-Security-Token with the security token.
Quick Hint
Section titled “Quick Hint”If you are using another programming language, you can use the following command in your terminal to generate a security token:
aws cognito-idp initiate-auth --auth-flow USER_PASSWORD_AUTH --region ap-southeast-2 --client-id 7jhe1lfkb5pvhbkicc3d14m0ej --auth-parameters USERNAME=<USER_LOGIN_EMAIL>,PASSWORD=<PASSWORD>API KEY
Section titled “API KEY”This authentication method is mainly used to fetch analytics data generated during your AI sessions. Please contact here or your Account Manager to sort out API keys for you. Further, you can also email us at support@unleashlive.com.