# C# JWT token invalid

**URL:** <https://devforum.zoom.us/t/c-jwt-token-invalid/5968>\
**Category:** API and Webhooks\
**Created:** [September 19, 2019, 10:15pm UTC](https://devforum.zoom.us/t/c-jwt-token-invalid/5968 "2019-09-19T22:15:47Z")\
**Posts on this page:** 17\
**Page:** 2

<div class="post-metadata">

**Author:** ![nvanderson](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/nvanderson/32/20082_2.png) [@nvanderson](https://devforum.zoom.us/u/nvanderson)\
**Post date:** [April 14, 2020, 3:05am UTC](https://devforum.zoom.us/t/c-jwt-token-invalid/5968/22 "2020-04-14T03:05:30Z")

</div>

I know it was driving me crazy for a few days.

And I believe their documentation needs a little update with a better explanation on the process.

---

<div class="post-metadata">

**Author:** ![Fitpass](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/fitpass/32/6007_2.png) [@Fitpass](https://devforum.zoom.us/u/Fitpass)\
**Post date:** [April 14, 2020, 8:42am UTC](https://devforum.zoom.us/t/c-jwt-token-invalid/5968/23 "2020-04-14T08:42:36Z")

</div>

Is there any way you could share your code with me? I’ve tried updating the NodeJS code that Zoom provides, and it still doesn’t work, even if I add the “iat” and “aud” fields to the JWT payload. ☹

```auto
const payload = {
    iss: config.APIKey,
    exp: (new Date()).getTime() + 60000,
    iat: (new Date()).getTime() + 0,
    aud: null,
};
const token = jwt.sign(payload, config.APISecret);

```

Thanks again! You rock!

---

<div class="post-metadata">

**Author:** ![nvanderson](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/nvanderson/32/20082_2.png) [@nvanderson](https://devforum.zoom.us/u/nvanderson)\
**Post date:** [April 14, 2020, 5:06pm UTC](https://devforum.zoom.us/t/c-jwt-token-invalid/5968/24 "2020-04-14T17:06:33Z")

</div>

private  
static  
string GetToken()

{

string Key =  
“Insert Yours”;

string Secret =  
“Insert Yours”;

var zone = TimeZoneInfo.FindSystemTimeZoneById( “Pacific  
Standard Time”);

var utcNow = DateTime.UtcNow;

var pacificNow = TimeZoneInfo.ConvertTimeFromUtc(utcNow, zone);

string s =  
null;

```
        TimeSpan t = pacificNow.AddMinutes(Convert.ToInt32(5)) -

```

new DateTime(1970, 1, 1);

int secondsSinceEpoch = (int)t.TotalSeconds;

```
        secondsSinceEpoch = 1607803200;

```

// this value needs to be set from ZOOM web app, it’s when the token expires

```
        TimeSpan secpacific = TimeZoneInfo.ConvertTimeFromUtc(utcNow, zone) -

```

new DateTime(1970, 1, 1);

int NowsecondsSinceEpoch = (int)secpacific.TotalSeconds;

var token =  
new { aud = s, iss = Key, exp = secondsSinceEpoch, iat = NowsecondsSinceEpoch };

```
        IJwtAlgorithm algorithm =

```

new HMACSHA256Algorithm();

```
        IJsonSerializer serializer =

```

new JsonNetSerializer();

```
        IBase64UrlEncoder urlEncoder =

```

new JwtBase64UrlEncoder();

return  
new JwtEncoder(algorithm, serializer, urlEncoder).Encode(token, Secret);

```
    }
```

---

<div class="post-metadata">

**Author:** ![Fitpass](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/fitpass/32/6007_2.png) [@Fitpass](https://devforum.zoom.us/u/Fitpass)\
**Post date:** [April 15, 2020, 12:53am UTC](https://devforum.zoom.us/t/c-jwt-token-invalid/5968/25 "2020-04-15T00:53:14Z")

</div>

Thanks for sharing your code. It doesn’t work for my app. I hope Zoom support can help me. We are a paying customer (like yourself) and honestly, we expect much better documentation with a JWT token tool that actually works. Thanks again.

I’ve opened a specific topic for our problem here: [JWT app returns "invalid token"](https://devforum.zoom.us/t/jwt-app-returns-invalid-token/13214)

---

<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:** [April 15, 2020, 8:33pm UTC](https://devforum.zoom.us/t/c-jwt-token-invalid/5968/26 "2020-04-15T20:33:59Z")

</div>

Hey @nvanderson,

Thanks for the feedback, we will make our docs more clear on how to generate the JWT Tokens.

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:** [April 15, 2020, 8:34pm UTC](https://devforum.zoom.us/t/c-jwt-token-invalid/5968/27 "2020-04-15T20:34:36Z")

</div>

Hey @Fitpass,

It seems your JWT App is effected with a cacheing issue we are having. Please private message me your account # so I can reset it.

Thanks,  
Tommy

---

<div class="post-metadata">

**Author:** ![alan.chen](https://avatars.discourse-cdn.com/v4/letter/a/e9bcb4/32.png) [@alan.chen](https://devforum.zoom.us/u/alan.chen)\
**Post date:** [May 5, 2020, 11:30pm UTC](https://devforum.zoom.us/t/c-jwt-token-invalid/5968/28 "2020-05-05T23:30:18Z")

</div>

Hi nvanderson,

Thanks for shareing your code. May I ask which dotnet package you’re using for HMACSHA256Algorithm? could you have package name and version which works for you.  
We suffer long time for this JWT token generation issue.

Thanks a lot.  
Alan

---

<div class="post-metadata">

**Author:** ![nvanderson](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/nvanderson/32/20082_2.png) [@nvanderson](https://devforum.zoom.us/u/nvanderson)\
**Post date:** [May 5, 2020, 11:45pm UTC](https://devforum.zoom.us/t/c-jwt-token-invalid/5968/29 "2020-05-05T23:45:22Z")

</div>

using JWT;

using JWT.Algorithms;

using JWT.Serializers;

using Newtonsoft.Json;

using Newtonsoft.Json.Linq;

using RestSharp;

using System;

using System.Collections.Generic;

using [System.IO](http://System.IO);

using [System.Net](http://System.Net);

using System.Text;

var zone = TimeZoneInfo.FindSystemTimeZoneById(“Pacific Standard Time”);

var utcNow = DateTime.UtcNow;

var pacificNow = TimeZoneInfo.ConvertTimeFromUtc(utcNow, zone);

string s = null;

TimeSpan t = pacificNow.AddMinutes(Convert.ToInt32(5)) - new DateTime(1970, 1, 1);

int secondsSinceEpoch = (int)t.TotalSeconds;

secondsSinceEpoch = 1607803200; // this value needs to be set from web app, after Dec 2020

TimeSpan secpacific = TimeZoneInfo.ConvertTimeFromUtc(utcNow, zone) - new DateTime(1970, 1, 1);

int NowsecondsSinceEpoch = (int)secpacific.TotalSeconds;

var token = new { aud = s, iss = Key, exp = secondsSinceEpoch, iat = NowsecondsSinceEpoch };

IJwtAlgorithm algorithm = new HMACSHA256Algorithm();

IJsonSerializer serializer = new JsonNetSerializer();

IBase64UrlEncoder urlEncoder = new JwtBase64UrlEncoder();

return new JwtEncoder(algorithm, serializer, urlEncoder).Encode(token, Secret);

---

<div class="post-metadata">

**Author:** ![alan.chen](https://avatars.discourse-cdn.com/v4/letter/a/e9bcb4/32.png) [@alan.chen](https://devforum.zoom.us/u/alan.chen)\
**Post date:** [May 6, 2020, 12:30am UTC](https://devforum.zoom.us/t/c-jwt-token-invalid/5968/30 "2020-05-06T00:30:03Z")

</div>

Thanks a lot, I’ll try that out

---

<div class="post-metadata">

**Author:** ![nvanderson](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/nvanderson/32/20082_2.png) [@nvanderson](https://devforum.zoom.us/u/nvanderson)\
**Post date:** [May 6, 2020, 12:46am UTC](https://devforum.zoom.us/t/c-jwt-token-invalid/5968/31 "2020-05-06T00:46:41Z")

</div>

In Visual Studio there is a suggestion pop-up. I just picked it from there to auto download and install. If you are using VS, are you getting suggestions? If not, I will look more in the code tomorrow. Good night.

---

<div class="post-metadata">

**Author:** ![alan.chen](https://avatars.discourse-cdn.com/v4/letter/a/e9bcb4/32.png) [@alan.chen](https://devforum.zoom.us/u/alan.chen)\
**Post date:** [May 6, 2020, 4:53pm UTC](https://devforum.zoom.us/t/c-jwt-token-invalid/5968/32 "2020-05-06T16:53:04Z")

</div>

Your code work like a charm. Thanks a lot.  
By the way, I use JetBrains Rider, and JWT package version 6.1.4.  
 ![image](https://us1.discourse-cdn.com/flex016/uploads/zoomdeveloper/original/2X/d/d55b33b173d43a882be023607ee978bf34b6103c.png)

---

<div class="post-metadata">

**Author:** ![nvanderson](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/nvanderson/32/20082_2.png) [@nvanderson](https://devforum.zoom.us/u/nvanderson)\
**Post date:** [May 6, 2020, 4:57pm UTC](https://devforum.zoom.us/t/c-jwt-token-invalid/5968/33 "2020-05-06T16:57:09Z")

</div>

packages\JWT.5.2.3\lib\net472\JWT.dll

namespace JWT.Algorithms

{

//

// Summary:

// HMAC using SHA-256

public sealed class HMACSHA256Algorithm : IJwtAlgorithm

{

public HMACSHA256Algorithm();

//

public string Name { get; }

//

public bool IsAsymmetric { get; }

//

public byte Sign(byte key, byte bytesToSign);

}

}

---

<div class="post-metadata">

**Author:** ![alan.chen](https://avatars.discourse-cdn.com/v4/letter/a/e9bcb4/32.png) [@alan.chen](https://devforum.zoom.us/u/alan.chen)\
**Post date:** [May 6, 2020, 5:12pm UTC](https://devforum.zoom.us/t/c-jwt-token-invalid/5968/34 "2020-05-06T17:12:22Z")

</div>

Just wondering, is any Zoom doc mention about this  
secondsSinceEpoch = 1607803200; // this value needs to be set from web app, after Dec 2020

As I tested with AddMinutes(), which still not work.  
(My local timezone is PST)

but when I add 12 hours as below, it works fine. I guess this related to timezone setting.

TimeSpan t = pacificNow.AddHours(12) - new DateTime(1970, 1, 1);  
int secondsSinceEpoch = (int)t.TotalSeconds;

I hope Zoom dev should provide standard example for handling case of different local timezone (convert to UTC)?

anyway, thanks for your sharing.

---

<div class="post-metadata">

**Author:** ![nvanderson](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/nvanderson/32/20082_2.png) [@nvanderson](https://devforum.zoom.us/u/nvanderson)\
**Post date:** [May 6, 2020, 5:27pm UTC](https://devforum.zoom.us/t/c-jwt-token-invalid/5968/35 "2020-05-06T17:27:28Z")

</div>

This value should be custom set by you manually on the JWT generation token page. It’s just a value I selected.

---

<div class="post-metadata">

**Author:** ![nvanderson](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/nvanderson/32/20082_2.png) [@nvanderson](https://devforum.zoom.us/u/nvanderson)\
**Post date:** [May 6, 2020, 5:38pm UTC](https://devforum.zoom.us/t/c-jwt-token-invalid/5968/36 "2020-05-06T17:38:02Z")

</div>

it all took me only 1 week to test and figure it…LOL

---

<div class="post-metadata">

**Author:** ![smaddu](https://avatars.discourse-cdn.com/v4/letter/s/b5a626/32.png) [@smaddu](https://devforum.zoom.us/u/smaddu)\
**Post date:** [May 8, 2020, 11:05pm UTC](https://devforum.zoom.us/t/c-jwt-token-invalid/5968/37 "2020-05-08T23:05:46Z")

</div>

Worked out like a charm with the JWT nuget package.

With framework 4.6+ you can use DateTimeOffset feature and convert to unix seconds for iat and exp.

In my case I did not need any timezone conversions.

---

<div class="post-metadata">

**Author:** ![michael.zoom](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/michael.zoom/32/37213_2.png) [@michael.zoom](https://devforum.zoom.us/u/michael.zoom)\
**Post date:** [May 13, 2020, 9:13pm UTC](https://devforum.zoom.us/t/c-jwt-token-invalid/5968/38 "2020-05-13T21:13:17Z")

</div>

Glad this is working, @nvanderson @alan.chen & @smaddu,

We’ll update our documentation here for more specifics on UTC in these tokens.

[Previous page](https://devforum.zoom.us/t/c-jwt-token-invalid/5968.md?page=1)
