Create Tokens
Overview
The Vonage Video Client SDKs require tokens for participants to use audio, video, and messaging functionality in your application. You can create a token using the Vonage Video API.
This how-to will go over:
- Creating a token
Before you start
Before you can create a token you first need to create a session. To learn about sessions and their role in a Vonage Video application, read the Sessions documentation.
Create a Token
To create a token, pass a Session ID to the generate client token function in the Vonage Server SDKs.
const { Vonage } = require('@vonage/server-sdk');
const vonage = new Vonage({
applicationId: VONAGE_APPLICATION_ID,
privateKey: VONAGE_PRIVATE_KEY,
baseUrl: string
});
try {
const token = await vonage.video.generateClientToken(sessionId);
} catch(error) {
console.error("Error generating Client Token: ", error);
}
import com.vonage.client.video.TokenOptions;
import com.vonage.client.video.VideoClient;
import java.time.Duration;
public class TokenGenerationSimple {
public static void main(String[] args) {
VonageClient vonageClient = VonageClient.builder()
.applicationId(VONAGE_APPLICATION_ID)
.privateKeyPath(VONAGE_PRIVATE_KEY)
.build();
VideoClient videoClient = vonageClient.getVideoClient();
String token = videoClient.generateToken(sessionId);
}
}
OpenTok opentok = new OpenTok(VONAGE_API_KEY, VONAGE_API_SECRET);
string token = opentok.GenerateToken(sessionId);
use Vonage\Client;
use Vonage\Client\Credentials\Keypair;
$credentials = new Keypair('VONAGE_PRIVATE_KEY', 'VONAGE_APPLICATION_ID');
$client = new Client($credentials);
$token = $client->video()->generateClientToken($sessionId);
from vonage import Client
client = Client(application_id='VONAGE_APPLICATION_ID', private_key='VONAGE_PRIVATE_KEY')
# Generate a Token from just a session_id (fetched from a database)
token = client.video.generate_token(session_id)
The function will return a string which is the token you will need for the Client SDKs. By default this token is able to both subscribe to and publish video. You additionally pass more options to the function which will allow you to customize the token. For more information check the Tokens documentation.