Last active
August 31, 2021 22:24
-
-
Save banagale/c1238d2c1351456a8e035ac77509d074 to your computer and use it in GitHub Desktop.
Python 3.6+ Implementation of Zoom.us SDK Signature Generation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import base64 | |
import hashlib | |
import hmac | |
def generate_signature(sig_ingredients: dict) -> str: | |
"""Python 3.6+ implementation of Zoom Signature Generation | |
Each request to start or join a meeting / webinar must | |
be verified by an encrypted signature authorizing the | |
user to enter. | |
https://marketplace.zoom.us/docs/sdk/native-sdks/web/essential/signature | |
:param sig_ingredients: used to create signature hash | |
:type sig_ingredients: object | |
:return: encrypted signature | |
:rtype: str | |
""" | |
mtg_number: str = str(sig_ingredients['meetingNumber']) | |
api_key: str = str(sig_ingredients['apiKey']) | |
role: str = str(sig_ingredients['role']) | |
api_secret: bytes = bytes(str(sig_ingredients['apiSecret']), 'utf-8') | |
ts: str = str(int(round(time.time() * 1000)) - 30000) | |
msg: str = api_key + mtg_number + ts + role | |
message: base64 = base64.b64encode(bytes(msg, 'utf-8')) | |
hash_value = hmac.new(api_secret, message, hashlib.sha256) | |
hash_value = base64.b64encode(hash_value.digest()) | |
hash_value: hashlib = hash_value.decode("utf-8") | |
tmp_string: str = f"{api_key}.{mtg_number}.{ts}.{role}.{hash_value}" | |
signature: bytes = base64.b64encode(bytes(tmp_string, "utf-8")) | |
signature: str = signature.decode("utf-8").rstrip("=") | |
return signature |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment