How to create JWT token using REST api in c#

This is what works for me on .Net Core 3.1.4
var setting = GetZoomSetting(); //This is where I picked the API Key and API Secret From

        var zone = TimeZoneInfo.FindSystemTimeZoneById("W. Central Africa Standard Time");
        var utcNow = DateTime.UtcNow;
        var westNow = TimeZoneInfo.ConvertTimeFromUtc(utcNow, zone);
        string s = null;
        TimeSpan t = westNow.AddMinutes(Convert.ToInt32(5)) - new DateTime(1970, 1, 1);
        int secondsSinceEpoch = (int)t.TotalSeconds;

        TimeSpan secpacific = TimeZoneInfo.ConvertTimeFromUtc(utcNow, zone) - new DateTime(1970, 1, 1);
        int NowsecondsSinceEpoch = (int)secpacific.TotalSeconds;
        var tokenHandler = new JwtSecurityTokenHandler();
        var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(setting.API.APISecret));
        var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);
        //Finally create a Token
        var header = new JwtHeader(creds);

        //Zoom Required Payload
        var payload = new JwtPayload
        {
            {"aud",s },
            { "iss", setting.API.APIKey},
            { "exp", secondsSinceEpoch },
            {"iat",NowsecondsSinceEpoch }
        };
        var token = new JwtSecurityToken(header, payload);
        var authtoken = tokenHandler.WriteToken(token);
        return authtoken;
2 Likes