This is a quick guide on using the Zoom API JWT authentication with C#. I found Zoom’s docs to be quite lacking, and had to experiment with this a bit to get it to work.
Zoom has two methods of authenticating: OAuth and JWT - JSON Web Token. They recommend using JWT for server-server API calls. So if you want the user to perform an operation on his own account from his own client, you should use user operations with OAuth. If, on the other hand, you want your server to open a Zoom meeting and wait for users to enter, and record the meeting on the server, there is no “Zoom client” involved in these operations, therefore you should use JWT authentication.
According to jwt.io:
JSON Web Tokens are an open, industry standard RFC 7519 method for representing claims securely between two parties.
What does that actually mean in practice?
First you’ll need to make a Zoom JWT app and get your API key and secret.
We’ll use Microsoft’s System.IdentityModel.Tokens.Jwt
nuget package to generate the JWT.
Open Nuget Package Manager, and add System.IdentityModel.Tokens.Jwt
by Microsoft.
Now add this piece of code to create your JWT token:
var tokenHandler = new System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler();
var now = DateTime.UtcNow;
var apiSecret = "<your API secret here>";
byte[] symmetricKey = Encoding.ASCII.GetBytes(apiSecret);
var tokenDescriptor = new SecurityTokenDescriptor
{
Issuer = "<your API key here>",
Expires = now.AddSeconds(30),
SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(symmetricKey), SecurityAlgorithms.HmacSha256),
};
var token = tokenHandler.CreateToken(tokenDescriptor);
var tokenString = tokenHandler.WriteToken(token);
Important things to note here:
symmetricKey
is what’s used to sign the JWT. This should be ASCII encoded, or else Zoom will reject it (this seems to be undocumented)Issuer
field is your Zoom API key.Expires
field can be set to any future date, but is recommended to be short-lived.SecurityAlgorithms.HmacSha256
hashing algorithm is supported by Zoom.Now you have your JWT in tokenString
.
To ensure that you have the correct token, you can use the JWT debugger Paste your JWT, and enter your secret in the secret field. You should see the headers including the HS256 algorithm and the JWT token type:
{
"alg": "HS256",
"typ": "JWT"
}
And the payload including the exp
expiry time in unix milliseconds, and iss
(issuer) with your API key:
{
"nbf": 1587197901,
"exp": 1587197931,
"iat": 1587197901,
"iss": "<your API key here>"
}
Now that you have the token from the server, you can use it to make API calls. Just concatenate the token to the Bearer
prefix and put it in the authorization
HTTP header (I’m using RestShart here):
var client = new RestClient("https://api.zoom.us/v2/users?status=active&page_size=30&page_number=1");
var request = new RestRequest(Method.GET);
request.AddHeader("content-type", "application/json");
request.AddHeader("authorization", String.Format("Bearer {0}", tokenString));
IRestResponse response = client.Execute(request);
And you should get all the account’s users. Enjoy :)