Node.js Python Java Ruby PHP
var jwt = require ( 'jsonwebtoken' ) ;
var uuid4 = require ( 'uuid4' ) ;
var app_access_key = '<app_access_key>' ;
var app_secret = '<app_secret>' ;
jwt. sign (
{
access_key: app_access_key,
type: 'management' ,
version: 2 ,
iat: Math . floor ( Date . now ( ) / 1000 ) ,
nbf: Math . floor ( Date . now ( ) / 1000 )
} ,
app_secret,
{
algorithm: 'HS256' ,
expiresIn: '24h' ,
jwtid: uuid4 ( )
} ,
function ( err, token ) {
console . log ( token) ;
}
) ;
import jwt
import uuid
import datetime
app_access_key = '<app_access_key>'
app_secret = '<app_secret>'
def generateManagementToken ( ) :
expires = 24 * 3600
now = datetime. datetime. utcnow( )
exp = now + datetime. timedelta( seconds= expires)
return jwt. encode( payload= {
'access_key' : app_access_key,
'type' : 'management' ,
'version' : 2 ,
'jti' : str ( uuid. uuid4( ) ) ,
'iat' : now,
'exp' : exp,
'nbf' : now
} , key= app_secret) . decode( 'utf-8' )
if __name__ == '__main__' :
print ( generateManagementToken( ) )
import java. time. Instant ;
import java. util. Date ;
import java. util. HashMap ;
import java. util. Map ;
import java. util. UUID;
import io. jsonwebtoken. Jwts ;
import io. jsonwebtoken. SignatureAlgorithm ;
private void generateManagementToken ( ) {
Map < String , Object > payload = new HashMap < > ( ) ;
payload. put ( "access_key" , "<app_access_key>" ) ;
payload. put ( "type" , "management" ) ;
payload. put ( "version" , 2 ) ;
String token = Jwts . builder ( ) . setClaims ( payload) . setId ( UUID. randomUUID ( ) . toString ( ) )
. setExpiration ( new Date ( System . currentTimeMillis ( ) + 86400 * 1000 ) )
. setIssuedAt ( Date . from ( Instant . ofEpochMilli ( System . currentTimeMillis ( ) - 60000 ) ) )
. setNotBefore ( new Date ( System . currentTimeMillis ( ) ) )
. signWith ( SignatureAlgorithm . HS256, "<app_secret>" . getBytes ( ) ) . compact ( ) ;
}
require 'jwt'
require 'securerandom'
$app_access_key = "<app_access_key>"
$app_secret = "<app_secret>"
def generateManagementToken ( )
now = Time . now
exp = now + 86400
payload = {
access_key: $app_access_key ,
type: "management" ,
version: 2 ,
jti: SecureRandom . uuid,
iat: now. to_i,
nbf: now. to_i,
exp: exp. to_i
}
token = JWT . encode( payload, $app_secret , 'HS256' )
return token
end
puts generateManagementToken
<?php
use Firebase\ JWT\ JWT ;
use Ramsey\ Uuid\ Uuid ;
$app_access_key = "<app_access_key>" ;
$app_secret = "<app_secret>"
$issuedAt = new DateTimeImmutable ( ) ;
$expire = $issuedAt -> modify ( '+24 hours' ) -> getTimestamp ( ) ;
$payload = [
'access_key' => $app_access_key ,
'type' => 'management' ,
'version' => 2 ,
'jti' => Uuid:: uuid4 ( ) -> toString ( ) ,
'iat' => $issuedAt -> getTimestamp ( ) ,
'nbf' => $issuedAt -> getTimestamp ( ) ,
'exp' => $expire ,
] ;
$token = JWT:: encode ( $payload , $app_secret , 'HS256' ) ;
?>
Warning
Don't expose management token to client apps.
App Token App Token will be used by Client-side apps while instantiating 100ms' SDKs. It is used for joining the conference. This token generating service should be hosted on your server
Sample app token generation code Node.js Python Java Ruby PHP
var jwt = require ( 'jsonwebtoken' ) ;
var uuid4 = require ( 'uuid4' ) ;
var app_access_key = '<app_access_key>' ;
var app_secret = '<app_secret>' ;
var payload = {
access_key: app_access_key,
room_id: '<room_id>' ,
user_id: '<user_id>' ,
role: '<role>' ,
type: 'app' ,
version: 2 ,
iat: Math . floor ( Date . now ( ) / 1000 ) ,
nbf: Math . floor ( Date . now ( ) / 1000 )
} ;
jwt. sign (
payload,
app_secret,
{
algorithm: 'HS256' ,
expiresIn: '24h' ,
jwtid: uuid4 ( )
} ,
function ( err, token ) {
console . log ( token) ;
}
) ;
import jwt
import uuid
import datetime
import sys
app_access_key = "<app_access_key>"
app_secret = "<app_secret>"
def generate ( room_id, user_id, role) :
expires = expires or 24 * 3600
now = datetime. datetime. utcnow( )
exp = now+ datetime. timedelta( seconds= expires)
return jwt. encode( payload= {
"access_key" : app_access_key,
"type" : "app" ,
"version" : 2 ,
"room_id" : room_id,
"user_id" : user_id,
"role" : role,
"jti" : str ( uuid. uuid4( ) ) ,
"exp" : exp,
"iat" : now,
"nbf" : now,
} , key= app_secret) . decode( "utf-8" )
if __name__ == "__main__" :
if len ( sys. argv) == 3 :
room_id = sys. argv[ 0 ]
user_id = sys. argv[ 1 ]
role = sys. argv[ 2 ]
print ( generate( room_id= room_id, user_id= user_id, role= role) )
import java. time. Instant ;
import java. util. Date ;
import java. util. HashMap ;
import java. util. Map ;
import java. util. UUID;
import io. jsonwebtoken. Jwts ;
import io. jsonwebtoken. SignatureAlgorithm ;
private void generateHmsClientToken ( ) {
Map < String , Object > payload = new HashMap < > ( ) ;
payload. put ( "access_key" , "<app_access_key>" ) ;
payload. put ( "room_id" , "<room_id>" ) ;
payload. put ( "user_id" , "<user_id>" ) ;
payload. put ( "role" , "<role>" ) ;
payload. put ( "type" , "app" ) ;
payload. put ( "version" , 2 ) ;
String token = Jwts . builder ( ) . setClaims ( payload) . setId ( UUID. randomUUID ( ) . toString ( ) )
. setExpiration ( new Date ( System . currentTimeMillis ( ) + 86400 * 1000 ) )
. setIssuedAt ( Date . from ( Instant . ofEpochMilli ( System . currentTimeMillis ( ) - 60000 ) ) )
. setNotBefore ( new Date ( System . currentTimeMillis ( ) ) )
. signWith ( SignatureAlgorithm . HS256, "<app_secret>" . getBytes ( ) ) . compact ( ) ;
}
require 'jwt'
require 'securerandom'
$app_access_key = "<app_access_key>"
$app_secret = "app_secret"
def generateAppToken ( room_id, user_id, role)
now = Time . now
exp = now + 86400
payload = {
access_key: $app_access_key ,
room_id: room_id,
user_id: user_id,
role: role,
type: "app" ,
jti: SecureRandom . uuid,
version: 2 ,
iat: now. to_i,
nbf: now. to_i,
exp: exp. to_i
}
token = JWT . encode( payload, $app_secret , 'HS256' )
end
puts generateAppToken "<room_id>" , "<user_id>" , "<role>"
<?php
use Firebase\ JWT\ JWT ;
use Ramsey\ Uuid\ Uuid ;
$issuedAt = new DateTimeImmutable ( ) ;
$expire = $issuedAt -> modify ( '+24 hours' ) -> getTimestamp ( ) ;
$accessKey = "<app_access_key>" ;
$secret = "<app_secret>" ;
$version = 2 ;
$type = "app" ;
$role = "<role>" ;
$roomId = "<room_id>" ;
$userId = "<user_id>" ;
$payload = [
'iat' => $issuedAt -> getTimestamp ( ) ,
'nbf' => $issuedAt -> getTimestamp ( ) ,
'exp' => $expire ,
'access_key' => $accessKey ,
'type' => "app" ,
'jti' => Uuid:: uuid4 ( ) -> toString ( )
'version' => 2 ,
'role' => $role ,
'room_id' => $roomId ,
'user_id' => $userId
] ;
$token = JWT:: encode (
$payload ,
$secret ,
'HS256'
) ;