Authenticate
The authenticate
function is the foundation of the Truvideo SDK. It securely initiates a session and prepares the SDK for capturing, uploading, and editing media.
This guide will walk you through integrating authentication into your project using the Truvideo Core Module.
Authentication Integration Guide
Prerequisites
Before you begin:
Make sure the Core module is integrated. See (Installation).
Request your API Key and Secret Key from Truvideo.
Get the API key and Secret Key from Truvideo Support
Step-by-Step Authentication Flow
Step 1: Prepare Your Credentials
Ensure you have:
API Key
Secret Key
External Id (If provided)
These are needed to sign each authentication request securely.
Step 2: Generate a Secure Signature
The SDK requires a hashed signature to validate each request. Follow this process to generate one:
Build the Payload
Use
TruvideoSdk.generatePayload()
to create a dynamic payload string.
Sign the Payload
Hash the payload using HMAC-SHA256 with your
Secret Key
.
Encode the Signature
Convert the hash into a hexadecimal string or base64 format.
Send the Signature
Include the signature in your authentication request.
const signature = await TruVideoSdkCore.toSha256String({
secretKey: secretKey,
payload: pay
});
Test Connection
Run tests to confirm successful integration.
import { TruVideoSdkCore } from '@trunpm/truvideo-capacitor-core-sdk';
async function auth() {
try {
const isAuth = await TruVideoSdkCore.isAuthenticated();
// Check if authentication token has expired
const isAuthExpired = await TruVideoSdkCore.isAuthenticationExpired();
//generate payload for authenticatio
const payload = await TruVideoSdkCore.generatePayload();
const mainPayload = String(payload.generatePayload);
const apiKey = "Enter API Key";
const secretKey = "Enter Secret Key ";
const signature = await TruVideoSdkCore.toSha256String({
secretKey: secretKey,
payload: mainPayload
});
const externalId = "";
// Authenticate only if not already authenticated or session expired
if (!isAuth.isAuthenticated || isAuthExpired.isAuthenticationExpired) {
await TruVideoSdkCore.authenticate({
apiKey: apiKey,
payload: mainPayload ,
signature: signature.signature,
externalId: externalId
});
}
// If user is authenticated successfully
await TruVideoSdkCore.initAuthentication();
//setAuthenticationValue("Authentication Successful");
} catch (error) {
console.error('Authentication Error:', error);
}
}
Final Steps: Test Your Integration
After implementing the authentication:
Run your application to verify that the SDK session initializes successfully.
Monitor the logs for any issues related to signatures or tokens.
Once confirmed, proceed to explore media capture, uploading, and editing features.
Thank you for using the Truvideo SDK. You're now authenticated and ready to explore all features!
Last updated
Was this helpful?