Skip to content

Instantly share code, notes, and snippets.

@linanw
Last active August 28, 2024 14:18
Show Gist options
  • Save linanw/9144d9bfc84da4076ab5beb04d4f9db1 to your computer and use it in GitHub Desktop.
Save linanw/9144d9bfc84da4076ab5beb04d4f9db1 to your computer and use it in GitHub Desktop.
Zoom SDK JWT Token Generation Script
#! /usr/bin/python3
## Thank @carson.zoom (https://devforum.zoom.us/u/carson.zoom/)
## It's based on script created carson.zoom.
## Zoom SDK JWT Token Generation Script
## This is for generating JWT token for Zoom SDK integration.
## SDK JWT token is different from the JWT token use for API integration.
## We will include API JWT token generation soon.
## Require: Python 3, pyjwt
## Prepare:
## 1. Install Python 3, https://www.python.org/downloads/.
## 2. Add pyjwt lib, pip3 install pyjwt
## 3. Update the variables below with your keys & secrets.
## 4. python3 zoom_jwtgen.py
meeting_sdk_key = ''
meeting_sdk_secret = ''
video_sdk_key = ''
video_sdk_secret = ''
import sys,datetime, time, json
try:
# pip3 install pyjwt
import jwt
except ImportError as err:
print(err)
print('Please install pyjwt package first, e.g. "pip3 install pyjwt"')
quit()
def printJSONPretty(dict):
print(json.dumps(dict, indent=4))
def verifyAndJwtEncode(payload, secret):
if(secret==''):
print('')
print('Please edit the script and add your key and secret at the begining.')
quit()
encoded=jwt.encode(payload, secret, algorithm='HS256')
return encoded
def generateMeetingJWT(opt):
key = meeting_sdk_key
secret = meeting_sdk_secret
iat = int(int(time.time()))
exp = int((datetime.datetime.today() + datetime.timedelta(days=2)).strftime("%s"))
tokenExp = int((datetime.datetime.today() + datetime.timedelta(hours=1)).strftime("%s"))
payload = {
'appKey': key,
'iat': iat,
'exp': exp,
'tokenExp': tokenExp
}
encoded=verifyAndJwtEncode(payload, secret)
print('payload:')
printJSONPretty(payload)
print('jwt token:')
print(encoded)
def generateVideoJWT():
iat = int(int(time.time()))
exp = int((datetime.datetime.today() + datetime.timedelta(days=2)).strftime("%s"))
payload = {
'app_key': video_sdk_key,
'version': 1,
'iat': iat,
'user_identity': '123',
'exp': exp,
'tpc': 'Test',
'session_key': '',
'role_type': 1 # role_type=1 means the user should be considered as the original host, role_type=0 means the user should be considered as a normal attendee.
}
encoded=verifyAndJwtEncode(payload, video_sdk_secret)
print('payload:')
printJSONPretty(payload)
print('jwt token:')
print(encoded)
def generateVideoJWTInput(topic, role):
iat = int(int(time.time()))
exp = int((datetime.datetime.today() + datetime.timedelta(hours=2)).strftime("%s"))
payload = {
'app_key': video_sdk_key,
'version': 1,
'user_identity': '123',
'iat': iat,
'exp': exp,
'tpc': topic,
'session_key': '',
'role_type': int(role)
}
encoded=verifyAndJwtEncode(payload, video_sdk_secret)
print('payload:')
printJSONPretty(payload)
print('jwt token:')
print(encoded)
print('===== JWT token generator ====')
print('[1]. Meeting SDK account')
print('[2]. Video SDK dev account (Default: tpc/SessionName: Test, RoleType: 1/host)')
print('[3]. Video SDK dev account (Custom...)')
print('[0]. Cancel and quit.')
opt = input('Need JWT for: ')
print('//====== JWT token')
if opt == '1':
generateMeetingJWT(opt)
elif opt == '2':
generateVideoJWT()
elif opt == '3':
topic = input('What == the topic? :')
role = input('What == the role type? (1 for original host, 0 for normal attendee)')
generateVideoJWTInput(topic, role)
elif opt == '0':
quit()
else:
print('Not supported')
print('//====== JWT token')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment