# 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:** 8\
**Page:** 3

<div class="post-metadata">

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

</div>

Glad they were able to help, @puneeth!

I will share this feedback with our team, to add more samples like this.

Best,  
Will

---

<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:** [December 6, 2020, 12:47am UTC](https://devforum.zoom.us/t/how-to-create-jwt-token-using-rest-api-in-c/6620/42 "2020-12-06T00:47:11Z")

</div>

Hi,

I am using the same code as yours. I had to make a few changes as we get the request related details from the DB. It worked perfectly in our dev and staging platform.

We deployed it into production and used the production API key and secret. The token generates successfully, and the expiry date also is as expected. However, when we make a request using the token, it throws `"Content":"{\"code\":124,\"message\":\"Access token is expired.\"}`

Below is my code for reference. Could you please let me know what is going wrong?

```
using Microsoft.IdentityModel.Tokens;
using System;
using System.Collections.Generic;
using System.IdentityModel.Tokens.Jwt;
using System.Linq;
using System.Text;

namespace Library.Zoom
{
    /// <summary>
    /// https://devforum.zoom.us/t/how-to-create-jwt-token-using-rest-api-in-c/6620/20?u=puneeth
    /// </summary>
    public class APIToken
    {
        private static string token;

        private static DateTime expiryDate;

        public static string GetToken()
        {
            if (!string.IsNullOrEmpty(token)
                && DateTime.Compare(DateTime.UtcNow, expiryDate) < 0)
            {
                return token;
            }
            else
            {
                try
                {
                    //Default expiry of the token in seconds
                    string expiresIn = "3600";

                    //Get api_key, api_secret, expires_in from DB

					DateTime expiresOn = DateTime.UtcNow.AddSeconds(Convert.ToDouble(expiresIn));

					long ts = (long)(expiresOn - new DateTime(1970, 1, 1)).TotalSeconds;

					//Create Security key using private key above:
					//note that latest version of JWT using Microsoft namespace instead of System
					SymmetricSecurityKey securityKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(apiSecret));

					//Also note that securityKey length should be >256b
					//so you have to make sure that your private key has a proper length
					SigningCredentials credentials = new SigningCredentials(securityKey, SecurityAlgorithms.HmacSha256);

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

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

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

					//Token to String so you can use it in your client
					token = handler.WriteToken(secToken);
					expiryDate = secToken.ValidTo;
                }
                catch (Exception ex)
                {
                    ins_error_log log = new ins_error_log();
                    log.runSP(ex, false);
                }
            }

            return token;
        }
    }
}
```

---

<div class="post-metadata">

**Author:** ![k.krylov](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/k.krylov/32/316_2.png) [@k.krylov](https://devforum.zoom.us/u/k.krylov)\
**Post date:** [December 6, 2020, 5:47am UTC](https://devforum.zoom.us/t/how-to-create-jwt-token-using-rest-api-in-c/6620/43 "2020-12-06T05:47:51Z")

</div>

I had similar issue on my prod server. Turned out time was out of sync. Make sure local time on your prod box is in sync, second option is to increase expiry time in minutes, bump it up to some larger value, I did not see any restrictions in the documentation.

---

<div class="post-metadata">

**Author:** ![will.zoom](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/will.zoom/32/14417_2.png) [@will.zoom](https://devforum.zoom.us/u/will.zoom)\
**Post date:** [December 7, 2020, 6:57pm UTC](https://devforum.zoom.us/t/how-to-create-jwt-token-using-rest-api-in-c/6620/44 "2020-12-07T18:57:14Z")

</div>

Thanks for sharing, @k.krylov!

---

<div class="post-metadata">

**Author:** ![engiibahaa](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/engiibahaa/32/1113_2.png) [@engiibahaa](https://devforum.zoom.us/u/engiibahaa)\
**Post date:** [December 14, 2020, 2:12pm UTC](https://devforum.zoom.us/t/how-to-create-jwt-token-using-rest-api-in-c/6620/45 "2020-12-14T14:12:38Z")

</div>

I need your help, I am trying to integrate zoom to my [ASP.Net](http://ASP.Net) Core project. After generating the token what should I do? I am really stuck at this point. I would be grateful if you could help.

---

<div class="post-metadata">

**Author:** ![will.zoom](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/will.zoom/32/14417_2.png) [@will.zoom](https://devforum.zoom.us/u/will.zoom)\
**Post date:** [December 15, 2020, 4:36pm UTC](https://devforum.zoom.us/t/how-to-create-jwt-token-using-rest-api-in-c/6620/46 "2020-12-15T16:36:10Z")

</div>

Hi @engiibahaa,

Once you’ve generated a JWT token, you can authenticate requests to any of our API endpoints. You can also utilize our Web SDK via JWT authentication:

> **[Web - Client SDKs - Zoom Software Development Kit (Zoom SDK)](https://marketplace.zoom.us/docs/sdk/native-sdks/web)**
>
> Zoom Web SDK
> 
> The Web SDK enables the development of video applications powered by Zoom's core framework inside an HTML5 web client through a highly opt...

If you have specific questions about either of these capabilities, just let us know.

Thanks,  
Will

---

<div class="post-metadata">

**Author:** ![apresence](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/apresence/32/20845_2.png) [@apresence](https://devforum.zoom.us/u/apresence)\
**Post date:** [January 10, 2021, 3:49pm UTC](https://devforum.zoom.us/t/how-to-create-jwt-token-using-rest-api-in-c/6620/47 "2021-01-10T15:49:22Z")

</div>

I have written a library to make working with Zoom’s Java Web Tokens (JWTs) in C# much easier:  
[https://github.com/apresence/ZoomJWT](https://github.com/apresence/ZoomJWT)

Enjoy!

---

<div class="post-metadata">

**Author:** ![will.zoom](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/will.zoom/32/14417_2.png) [@will.zoom](https://devforum.zoom.us/u/will.zoom)\
**Post date:** [January 11, 2021, 4:49pm UTC](https://devforum.zoom.us/t/how-to-create-jwt-token-using-rest-api-in-c/6620/48 "2021-01-11T16:49:17Z")

</div>

Thanks for sharing, @apresence! I’m sure our community will find this helpful. 🙂

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