Authenticate
Deprication Warning
This document is archived and will be maintained only until September 15. Please refer to the latest documentation here for updated information.
The authenticate function is used for initializing the SDK. Before calling this function, make sure that you have set the event listeners, otherwise, no authentication events can be trigger
TruvideoSdk.authenticate(apiKey: Constant.apiKey, payload: payload, signature: signature)apiKey (required) String
The unique API key that will be provided by Truvideo team
payload (required) String
The payload is a string that can be generated by generatePayload()
signature (required) String
The signature is a string that is generated by encoding payload with SHA256 using a secret key
Example
/// Authentication process
func authenticate() async {
/// Verify if the user is already authenticated or if the session is active or expired..
let isAuthenticated = TruvideoSdk.isAuthenticated
let isAuthenticationExpired = TruvideoSdk.isAuthenticationExpired
let apiKey = "your-api-key"
let payload = TruvideoSdk.generatePayload()
/// The payload string is transformed into an encrypted string using the SHA256 algorithm.
let signature = payload.toSha256String(using: "your-secret-key")
do {
if !isAuthenticated || isAuthenticationExpired {
/// Initialize a session when the user is not authenticated.
/// - Parameters:
/// - API_Key : Provided by TruVideo team
/// - Payload : generated by sdk TruvideoSdk.generatePayload() every time you have to create new payload
/// - Signature: encrypted string payload using the SHA256 algorithm with "secret key"
/// - Secret_Key: secret key is also provided by TruVideo team
try await TruvideoSdk.authenticate(apiKey: apiKey, payload: payload, signature: signature)
}
/// Initialize a session when the user is already authenticated.
try await TruvideoSdk.initAuthentication()
} catch {
// handle error
}
}
Clear Authentication
The clear function deletes the current session and erases all associated authentication data.
Syntax
clearAuthentication()Example
TruvideoSdk.clearAuthentication()Last updated
Was this helpful?