How to create JWT token using REST api in c#

Hi,

how to create JWT token using REST api in c#

1 Like

Hey @vaibhav.bhosale, thanks for posting and using Zoom!

You can reference our JWT with Zoom guide:

I would suggest using one of the C# libraries here:

Possible duplicate post with more info:

Thanks,
Tommy

As I recall, you need to create the token on Zoom web-page first. Put some future expiration date, then use that date in the code. You should see the same token during debugging.

Thanks @nvanderson, yes you can do that!

@vaibhav.bhosale, go here: https://marketplace.zoom.us/develop/create, create a JWT app, then on the “App Credentials” page you will see an already generated JWT token:

Thanks,
Tommy

Hi ! I used Microsoft.IdentityModel.Tokens and System.IdentityModel.Tokens.Jwt to create C# command line tool that can generate JWT token for Zoom. In payload you have to use “iss” end “exp”. Sorry, I can’t share my code exactly…

Thanks for posting @lgelman! :slight_smile:

Is the tool you made internal, or do you plan on sharing it?

-Tommy

using System;
using System.Text;
using System.IdentityModel.Tokens.Jwt;
using Microsoft.IdentityModel.Tokens;
namespace Zoom 
{
    public static class ZoomToken
    {
        public static string ZoomToken(){
		// Token will be good for 20 minutes
        DateTime Expiry = DateTime.UtcNow.AddMinutes(20);

		string ApiKey = "YOUR_API_KEY_HERE");
		string ApiSecret = "YOUR_API_SECRET_HERE";

		int ts = (int)(Expiry - new DateTime(1970, 1, 1)).TotalSeconds;

		// Create Security key  using private key above:
		var securityKey = new Microsoft.IdentityModel.Tokens.SymmetricSecurityKey(Encoding.UTF8.GetBytes(ApiSecret));

		// length should be >256b
		var credentials = new SigningCredentials(securityKey, SecurityAlgorithms.HmacSha256);

		//Finally create a Token
		var header = new JwtHeader(credentials);

		//Zoom Required Payload
		var payload = new JwtPayload
		{
			{ "iss", ApiKey},
			{ "exp", ts },
		};

		var secToken = new JwtSecurityToken(header, payload);
		var handler = new JwtSecurityTokenHandler();

		// Token to String so you can use it in your client
		var tokenString = handler.WriteToken(secToken);
		
        return tokenString;
        }
    }
}

Thanks @k.krylov! :slight_smile:

-Tommy