# C# IRestRespose Fails - JWT

**URL:** <https://devforum.zoom.us/t/c-irestrespose-fails-jwt/23575>\
**Category:** API and Webhooks\
**Created:** [July 8, 2020, 4:44pm UTC](https://devforum.zoom.us/t/c-irestrespose-fails-jwt/23575 "2020-07-08T16:44:09Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![jim.hubbard](https://avatars.discourse-cdn.com/v4/letter/j/4491bb/32.png) [@jim.hubbard](https://devforum.zoom.us/u/jim.hubbard)\
**Post date:** [July 8, 2020, 4:44pm UTC](https://devforum.zoom.us/t/c-irestrespose-fails-jwt/23575/1 "2020-07-08T16:44:09Z")

</div>

I am running the following piece of code for a test. I get back a valid token. I tested it at JWT…  
The response returns a response.IsSuccessful as false and no content. I expected a list of users…

I put my API key and Secret Key in where it is commented.

Thanks for any help

```
     var tokenHandler = new System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler();
        var now = DateTime.UtcNow;
        var apiSecret = "<your API secret here>";
        byte[] symmetricKey = Encoding.ASCII.GetBytes(apiSecret);

        var tokenDescriptor = new SecurityTokenDescriptor
        {
            Issuer = "<your API key here>",
            Expires = now.AddSeconds(30),
            SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(symmetricKey), SecurityAlgorithms.HmacSha256),
        };
        var token = tokenHandler.CreateToken(tokenDescriptor);

        var tokenString = tokenHandler.WriteToken(token);

        var client = new RestClient("https://api.zoom.us/v2/users?status=active&page_size=30&page_number=1");
        var request = new RestRequest(Method.GET);
        request.AddHeader("content-type", "application/json");
        request.AddHeader("authorization", String.Format("Bearer {0}", tokenString));

        IRestResponse response = client.Execute(request);

        MessageBox.Show(response.IsSuccessful.ToString());
```

---

<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 10, 2020, 4:13pm UTC](https://devforum.zoom.us/t/c-irestrespose-fails-jwt/23575/2 "2020-07-10T16:13:57Z")

</div>

Hey @jim.hubbard,

Can you please share the response JSON?

Thanks,  
Tommy

---

<div class="post-metadata">

**Author:** ![jim.hubbard](https://avatars.discourse-cdn.com/v4/letter/j/4491bb/32.png) [@jim.hubbard](https://devforum.zoom.us/u/jim.hubbard)\
**Post date:** [July 10, 2020, 5:19pm UTC](https://devforum.zoom.us/t/c-irestrespose-fails-jwt/23575/3 "2020-07-10T17:19:48Z")

</div>

I am not getting any response. Null Response.  
error: InnerException = {“Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.”}

I tried another piece of code and got the same result.

```
   private void GetAccountUsers(string ZoomApiKey, string ZoomApiSecret)
    {
        try
        {

            ZoomToken zt = new ZoomToken();
            string Token = zt.GetToken(ZoomApiKey,ZoomApiSecret);

            //Create new Request
            string BaseUrl = "https://api.zoom.us/v2/users?status=active&page_size=300&page_number=1";
            HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(BaseUrl);
            myHttpWebRequest.Method = "GET";
            myHttpWebRequest.ContentType = "application/json;";
            myHttpWebRequest.Accept = "application/json;";
            myHttpWebRequest.Headers.Add("Authorization", String.Format("Bearer {0}", Token));

            //Get the associated response for the above request

```

//WHEN IT GETS HERE I GET AN ERROR. THE RESPONSE IN NULL.  
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();

```
            using (StreamReader MyStreamReader = new StreamReader(myHttpWebResponse.GetResponseStream(), true))
            {
                this.AccountUsers = JsonConvert.DeserializeObject<AccountUsers>(MyStreamReader.ReadToEnd());
            }

            myHttpWebResponse.Close();
            myHttpWebResponse.Dispose();

        }
        catch (WebException ex)
        {
            int errorCode = (int)((HttpWebResponse)ex.Response).StatusCode;
            if (errorCode != 0)
            {
                ErrorCode = errorCode;
                Stream MyStream = ex.Response.GetResponseStream();
                StreamReader MyStreamReader = new StreamReader(MyStream, true);
                this.ZoomException = JsonConvert.DeserializeObject<ZoomErrorResponse>(MyStreamReader.ReadToEnd());

                //would be nice to check ZoomException for Null before throwing
                throw new Exception(this.ZoomException.Message);
            }
        }
    }
```

---

<div class="post-metadata">

**Author:** ![jim.hubbard](https://avatars.discourse-cdn.com/v4/letter/j/4491bb/32.png) [@jim.hubbard](https://devforum.zoom.us/u/jim.hubbard)\
**Post date:** [July 10, 2020, 6:30pm UTC](https://devforum.zoom.us/t/c-irestrespose-fails-jwt/23575/4 "2020-07-10T18:30:41Z")

</div>

I tried using Curl and got an invalid token. I copied the toke from my app I made it valid for a day.

$ Curl -X POST -H “Accept:application/json” -H “Authorization:eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOm51bGwsImlzcyI6Im1JU2pDVGFCUVh1aDhRb20yNEZabHciLCJleHAiOjE1OTQ0OTE5MTIsImlhdCI6MTU5NDQwNTUxMn0.GLt8txVLUc2LpFR9Da2Lk3tzppX3lI\_ejcVq0A7VE70” [https://api.zoom.us/v2/users?status=active&page\_size=300&page\_number=1](https://api.zoom.us/v2/users?status=active&page_size=300&page_number=1)  
[2] 603  
[3] 604  
[1] Done Curl -X POST -H “Accept:application/json” -H “Authorization:eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOm51bGwsImlzcyI6Im1JU2pDVGFCUVh1aDhRb20yNEZabHciLCJleHAiOjE1OTQzNzk2ODAsImlhdCI6MTU5NDM3OTM4MH0.FMNM1sqC3XgEm4PnmvEoTx0yUgVdfUUAGpnuXcj1XlY” [https://api.zoom.us/v2/users?status=active](https://api.zoom.us/v2/users?status=active)  
[3]+ Done page\_size=300

jim.hubbard@UIH001900 MINGW64 /  
$ % Total % Received % Xferd Average Speed Time Time Time Current  
Dload Upload Total Spent Left Speed  
100 46 0 46 0 0 81 0 --:–:-- --:–:-- --:–:-- 81{“code”:124,“message”:“Invalid access token.”}

---

<div class="post-metadata">

**Author:** ![jim.hubbard](https://avatars.discourse-cdn.com/v4/letter/j/4491bb/32.png) [@jim.hubbard](https://devforum.zoom.us/u/jim.hubbard)\
**Post date:** [July 10, 2020, 6:32pm UTC](https://devforum.zoom.us/t/c-irestrespose-fails-jwt/23575/5 "2020-07-10T18:32:05Z")

</div>

I am going to regenerate the secret key and try again…

---

<div class="post-metadata">

**Author:** ![jim.hubbard](https://avatars.discourse-cdn.com/v4/letter/j/4491bb/32.png) [@jim.hubbard](https://devforum.zoom.us/u/jim.hubbard)\
**Post date:** [July 13, 2020, 10:15pm UTC](https://devforum.zoom.us/t/c-irestrespose-fails-jwt/23575/6 "2020-07-13T22:15:11Z")

</div>

code: 124  
message: “Invalid access token.”

---

<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 16, 2020, 6:22pm UTC](https://devforum.zoom.us/t/c-irestrespose-fails-jwt/23575/7 "2020-07-16T18:22:07Z")

</div>

Hey @jim.hubbard,

When you are setting your JWT Authorization header, you are missing the bearer keyword.

`"Authorization": "Bearer JWT_TOKEN_HERE"`

Thanks,  
Tommy

---

<div class="post-metadata">

**Author:** ![jim.hubbard](https://avatars.discourse-cdn.com/v4/letter/j/4491bb/32.png) [@jim.hubbard](https://devforum.zoom.us/u/jim.hubbard)\
**Post date:** [July 16, 2020, 6:34pm UTC](https://devforum.zoom.us/t/c-irestrespose-fails-jwt/23575/8 "2020-07-16T18:34:58Z")

</div>

Hi Tommy,

I finally got this working. I regenerated my JWT secret and that fixed the problem. I am working on some of the functionality now…

Thanks for getting back to me.

J

---

<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 20, 2020, 10:58pm UTC](https://devforum.zoom.us/t/c-irestrespose-fails-jwt/23575/9 "2020-07-20T22:58:14Z")

</div>

Happy to hear you got it working! 🙂

Thanks,  
Tommy

---

<div class="post-metadata">

**Author:** ![DeveloperBot](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/developerbot/32/12632_2.png) [@DeveloperBot](https://devforum.zoom.us/u/DeveloperBot)\
**Post date:** [August 21, 2020, 10:47pm UTC](https://devforum.zoom.us/t/c-irestrespose-fails-jwt/23575/10 "2020-08-21T22:47:28Z")

</div>

Closed on August 21, 2020, 10:47pm UTC


