# How to create JWT token using REST api in c#

**URL:** <https://devforum.zoom.us/t/how-to-create-jwt-token-using-rest-api-in-c/6620>\
**Category:** API and Webhooks\
**Created:** [November 12, 2019, 11:50am UTC](https://devforum.zoom.us/t/how-to-create-jwt-token-using-rest-api-in-c/6620 "2019-11-12T11:50:01Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![kshitij.gugale](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/kshitij.gugale/32/4654_2.png) [@kshitij.gugale](https://devforum.zoom.us/u/kshitij.gugale)\
**Post date:** [July 9, 2020, 7:23am UTC](https://devforum.zoom.us/t/how-to-create-jwt-token-using-rest-api-in-c/6620/21 "2020-07-09T07:23:44Z")

</div>

Thanks @k.krylov for the code. You saved my day. It has fixed now.  
The issue was with this line:

var credentials = new Microsoft.IdentityModel.Tokens.SigningCredentials(securityKey, SecurityAlgorithms.HmacSha256Signature);

I have updated line to below one and it worked. Thanks a ton.  
var credentials = new SigningCredentials(securityKey, SecurityAlgorithms.HmacSha256);

I think when I added that line it was taking a reference from some other DLL and hence it was asking to add HmacSha256Signature algoritham.

Again, thank you!

---

<div class="post-metadata">

**Author:** ![tommy](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/tommy/32/72769_2.png) [@tommy](https://devforum.zoom.us/u/tommy)\
**Post date:** [July 14, 2020, 5:14pm UTC](https://devforum.zoom.us/t/how-to-create-jwt-token-using-rest-api-in-c/6620/22 "2020-07-14T17:14:45Z")

</div>

Happy to hear your issue is fixed @kshitij.gugale! 🙂

Thanks for your help @k.krylov! 🙂

-Tommy

---

<div class="post-metadata">

**Author:** ![trupti.patlekar](https://avatars.discourse-cdn.com/v4/letter/t/58956e/32.png) [@trupti.patlekar](https://devforum.zoom.us/u/trupti.patlekar)\
**Post date:** [July 28, 2020, 10:45am UTC](https://devforum.zoom.us/t/how-to-create-jwt-token-using-rest-api-in-c/6620/23 "2020-07-28T10:45:37Z")

</div>

Hi team,  
In my web application , I am calling zoom create api using jwt token which is generated by using api\_key and secret key which giving me response as expected on local server (development environment).But same on production giving me “” blank response.

What to do in order to get proper response on production.

Same apikey and secret key are used to generate jwt token on production.  
Thanks  
Trupti

---

<div class="post-metadata">

**Author:** ![harshit.singhal](https://avatars.discourse-cdn.com/v4/letter/h/e0b2c6/32.png) [@harshit.singhal](https://devforum.zoom.us/u/harshit.singhal)\
**Post date:** [July 29, 2020, 7:34pm UTC](https://devforum.zoom.us/t/how-to-create-jwt-token-using-rest-api-in-c/6620/24 "2020-07-29T19:34:59Z")

</div>

Hello,

I have used this code. But i Am getting an error of assembly files…

---

<div class="post-metadata">

**Author:** ![trupti.patlekar](https://avatars.discourse-cdn.com/v4/letter/t/58956e/32.png) [@trupti.patlekar](https://devforum.zoom.us/u/trupti.patlekar)\
**Post date:** [July 30, 2020, 7:34am UTC](https://devforum.zoom.us/t/how-to-create-jwt-token-using-rest-api-in-c/6620/25 "2020-07-30T07:34:30Z")

</div>

hi can u please tell me for generating jwt token the api key and secret key u are using is of which type of account?  
As i m using basic account type and its free account  
i am getting meeting response when api call locally but not getting any response not even error when try to calling from different server where i published my code.

---

<div class="post-metadata">

**Author:** ![mike.gold](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/mike.gold/32/12463_2.png) [@mike.gold](https://devforum.zoom.us/u/mike.gold)\
**Post date:** [July 30, 2020, 11:19am UTC](https://devforum.zoom.us/t/how-to-create-jwt-token-using-rest-api-in-c/6620/26 "2020-07-30T11:19:51Z")

</div>

Thank You, Thank You, Thank You, @k.krylov. Your Zoom Token Class worked perfectly. I made sure to give you credit in our source code. For better of worse, the only thing I added was a “Timeout” parameter to help us manage token expiration in an administrative module setting on our public Zoom meeting registration control. Here’s an image of just the slight modification. Thanks Again… Your class saved me tons of time.

 ![k-krylov-ZoomJWTClass-WithTimeoutPerameter](https://us1.discourse-cdn.com/flex016/uploads/zoomdeveloper/original/2X/b/bccb8094cd09717f8db9007cadc18cc10e5d44ef.jpeg)

---

<div class="post-metadata">

**Author:** ![tommy](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/tommy/32/72769_2.png) [@tommy](https://devforum.zoom.us/u/tommy)\
**Post date:** [August 3, 2020, 9:41pm UTC](https://devforum.zoom.us/t/how-to-create-jwt-token-using-rest-api-in-c/6620/27 "2020-08-03T21:41:43Z")

</div>

Happy to hear you got it working @mike.gold! 🙂

-Tommy

---

<div class="post-metadata">

**Author:** ![tommy](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/tommy/32/72769_2.png) [@tommy](https://devforum.zoom.us/u/tommy)\
**Post date:** [August 3, 2020, 9:42pm UTC](https://devforum.zoom.us/t/how-to-create-jwt-token-using-rest-api-in-c/6620/28 "2020-08-03T21:42:02Z")

</div>

Hey @harshit.singhal,

Please share steps to reproduce the issue.

Thanks,  
Tommy

---

<div class="post-metadata">

**Author:** ![tommy](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/tommy/32/72769_2.png) [@tommy](https://devforum.zoom.us/u/tommy)\
**Post date:** [August 3, 2020, 9:42pm UTC](https://devforum.zoom.us/t/how-to-create-jwt-token-using-rest-api-in-c/6620/29 "2020-08-03T21:42:26Z")

</div>

Hey @trupti.patlekar,

Please share steps to reproduce your issue.

Thanks,  
Tommy

---

<div class="post-metadata">

**Author:** ![harshit.singhal](https://avatars.discourse-cdn.com/v4/letter/h/e0b2c6/32.png) [@harshit.singhal](https://devforum.zoom.us/u/harshit.singhal)\
**Post date:** [August 4, 2020, 2:24am UTC](https://devforum.zoom.us/t/how-to-create-jwt-token-using-rest-api-in-c/6620/30 "2020-08-04T02:24:16Z")

</div>

Hey,

Please find the below code for your reference.

public string GenerateToken ()  
{  
var tokenHandler = new JwtSecurityTokenHandler();  
var now = DateTime.UtcNow;  
var apiSecret = “”;  
byte symmetricKey = Encoding.ASCII.GetBytes(apiSecret);

var tokenDescriptor = new Microsoft.IdentityModel.Tokens.SecurityTokenDescriptor  
{  
Issuer = “”,  
Expires = now.AddSeconds(30),  
SigningCredentials = new Microsoft.IdentityModel.Tokens.SigningCredentials(new Microsoft.IdentityModel.Tokens.SymmetricSecurityKey(symmetricKey), Microsoft.IdentityModel.Tokens.SecurityAlgorithms.HmacSha256),  
};  
var token = tokenHandler.CreateToken(tokenDescriptor);

var tokenString = tokenHandler.WriteToken(token);  
}

 ![image.png](https://us1.discourse-cdn.com/flex016/uploads/zoomdeveloper/original/2X/5/511ed140e0ca09e97380bd11e7e4e0a83d08281f.png)

I think the problem is with dll. Can you tell me the version for dll

---

<div class="post-metadata">

**Author:** ![trupti.patlekar](https://avatars.discourse-cdn.com/v4/letter/t/58956e/32.png) [@trupti.patlekar](https://devforum.zoom.us/u/trupti.patlekar)\
**Post date:** [August 4, 2020, 6:19am UTC](https://devforum.zoom.us/t/how-to-create-jwt-token-using-rest-api-in-c/6620/31 "2020-08-04T06:19:20Z")

</div>

thank you . I got route cause of my issue which is the server where i am executing API don’t have zoom access.

---

<div class="post-metadata">

**Author:** ![trupti.patlekar](https://avatars.discourse-cdn.com/v4/letter/t/58956e/32.png) [@trupti.patlekar](https://devforum.zoom.us/u/trupti.patlekar)\
**Post date:** [August 4, 2020, 4:47pm UTC](https://devforum.zoom.us/t/how-to-create-jwt-token-using-rest-api-in-c/6620/32 "2020-08-04T16:47:31Z")

</div>

Now the server where I am calling zoom api for create meeting still providing response as blank.  
i am using c# [asp.net](http://asp.net) core application where i have implemented function as below. In that function jwt token geerated using ZoomToken() function.  
This is working fine in my local server but giving blank response when run on UAT server whish i used to host application.  
Kindly find the following steps:  
this function i am calling from our iis server  
var client = new RestClient(“[https://api.zoom.us/v2/users/me/meetings](https://api.zoom.us/v2/users/me/meetings)”);  
var request = new RestRequest(Method.POST);  
request.AddHeader(“content-type”, “application/json”);  
request.AddHeader(“authorization”, String.Format(“Bearer {0}”,ZoomUtility.ZoomToken()));  
request.AddParameter(“application/json”, “{“topic”:“Meeting”,“type”:“1”,“start\_time”:”" + sdate + “”,“duration”:“120”,“schedule\_for”:null,“timezone”:“Asia/Calcutta”,“password”:"",“agenda”:"",“recurrence”:{“type”:“2”,“repeat\_interval”:"",“weekly\_days”:"",“monthly\_day”:"",“monthly\_week”:"",“monthly\_week\_day”:"",“end\_times”:"",“end\_date\_time”:"" + edate + “”},“settings”:{“host\_video”:true,“participant\_video”:false,“cn\_meeting”:false,“in\_meeting”:true,“join\_before\_host”:false,“mute\_upon\_entry”:false,“watermark”:false,“use\_pmi”:false,“approval\_type”:“1”,“registration\_type”:“1”,“audio”:"",“auto\_recording”:"",“enforce\_login”:"",“enforce\_login\_domains”:"",“alternative\_hosts”:"",“global\_dial\_in\_countries”:[""],“registrants\_email\_notification”:true}}", ParameterType.RequestBody);  
IRestResponse response = client.Execute(request);  
var content = response.Content;

public static string ZoomToken()  
{  
// Token will be good for 20 minutes  
DateTime Expiry = DateTime.UtcNow.AddMinutes(1440);

```
        int ts = (int)(Expiry - new DateTime(1970, 1, 1)).TotalSeconds;
        string apiSecret = ZoomAPISecretString();
        string apiKey = ZoomAppKeyString();
        // Create Security key using private key above:
        var securityKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(apiSecret));

        // I did changes in below line because DLL needed HmacSha256Signature instead of HmacSha256
        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;
    }
```

---

<div class="post-metadata">

**Author:** ![trupti.patlekar](https://avatars.discourse-cdn.com/v4/letter/t/58956e/32.png) [@trupti.patlekar](https://devforum.zoom.us/u/trupti.patlekar)\
**Post date:** [August 5, 2020, 4:22pm UTC](https://devforum.zoom.us/t/how-to-create-jwt-token-using-rest-api-in-c/6620/33 "2020-08-05T16:22:03Z")

</div>

Hi , My issue has been resolved by my network team .it was access right issue.

---

<div class="post-metadata">

**Author:** ![tommy](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/tommy/32/72769_2.png) [@tommy](https://devforum.zoom.us/u/tommy)\
**Post date:** [August 6, 2020, 7:03pm UTC](https://devforum.zoom.us/t/how-to-create-jwt-token-using-rest-api-in-c/6620/34 "2020-08-06T19:03:10Z")

</div>

Happy to hear you got it sorted out! 🙂

Thanks,  
Tommy

---

<div class="post-metadata">

**Author:** ![tommy](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/tommy/32/72769_2.png) [@tommy](https://devforum.zoom.us/u/tommy)\
**Post date:** [August 6, 2020, 7:03pm UTC](https://devforum.zoom.us/t/how-to-create-jwt-token-using-rest-api-in-c/6620/35 "2020-08-06T19:03:26Z")

</div>

Thanks for your suggestions @harshit.singhal! 🙂

-Tommy

---

<div class="post-metadata">

**Author:** ![harshit.singhal](https://avatars.discourse-cdn.com/v4/letter/h/e0b2c6/32.png) [@harshit.singhal](https://devforum.zoom.us/u/harshit.singhal)\
**Post date:** [August 7, 2020, 2:51am UTC](https://devforum.zoom.us/t/how-to-create-jwt-token-using-rest-api-in-c/6620/36 "2020-08-07T02:51:41Z")

</div>

Hey,

Can you help me out in this issue? Please send me the resolution asap.

---

<div class="post-metadata">

**Author:** ![tommy](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/tommy/32/72769_2.png) [@tommy](https://devforum.zoom.us/u/tommy)\
**Post date:** [August 7, 2020, 8:33pm UTC](https://devforum.zoom.us/t/how-to-create-jwt-token-using-rest-api-in-c/6620/37 "2020-08-07T20:33:31Z")

</div>

Hey @harshit.singhal,

Please see the JWT docs and Libraries here:

> **[JSON Web Tokens (JWT) - Authorization - Documentation](https://marketplace.zoom.us/docs/guides/auth/jwt)**
>
> JWT With Zoom
> 
> The Zoom API uses JSON Web Tokens (JWT) to authenticate account-level access. These tokens offer a method to establish secure server-to-s...

> **[JWT.IO](https://jwt.io/#libraries-io)**
>
> JSON Web Tokens are an open, industry standard RFC 7519 method for representing claims securely between two parties.

Thanks,  
Tommy

---

<div class="post-metadata">

**Author:** ![harshit.singhal](https://avatars.discourse-cdn.com/v4/letter/h/e0b2c6/32.png) [@harshit.singhal](https://devforum.zoom.us/u/harshit.singhal)\
**Post date:** [August 8, 2020, 4:06am UTC](https://devforum.zoom.us/t/how-to-create-jwt-token-using-rest-api-in-c/6620/38 "2020-08-08T04:06:53Z")

</div>

Hey Tommy,

Thanks a lot to you. My Problem is resolved.

---

<div class="post-metadata">

**Author:** ![tommy](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/tommy/32/72769_2.png) [@tommy](https://devforum.zoom.us/u/tommy)\
**Post date:** [August 10, 2020, 6:47am UTC](https://devforum.zoom.us/t/how-to-create-jwt-token-using-rest-api-in-c/6620/39 "2020-08-10T06:47:53Z")

</div>

Happy to hear you got the issue sorted out! 🙂

Thanks,  
Tommy

---

<div class="post-metadata">

**Author:** ![puneeth](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/puneeth/32/18687_2.png) [@puneeth](https://devforum.zoom.us/u/puneeth)\
**Post date:** [November 12, 2020, 6:15pm UTC](https://devforum.zoom.us/t/how-to-create-jwt-token-using-rest-api-in-c/6620/40 "2020-11-12T18:15:43Z")

</div>

@k.krylov @mike.gold Both of your codes helped a lot. You saved spending a ton of time looking into the docs.

Tommy Gaessler, could you please update the docs with the sample code to get JWT tokens? It will save a lot of time for new developers.

[Previous page](https://devforum.zoom.us/t/how-to-create-jwt-token-using-rest-api-in-c/6620.md?page=1)

[Next page](https://devforum.zoom.us/t/how-to-create-jwt-token-using-rest-api-in-c/6620.md?page=3)
