# Valid JWT using curl, not when using node.js

**URL:** <https://community.auth0.com/t/valid-jwt-using-curl-not-when-using-node-js/9703>\
**Category:** JWT.io\
**Created:** [March 5, 2018, 1:53am UTC](https://community.auth0.com/t/valid-jwt-using-curl-not-when-using-node-js/9703 "2018-03-05T01:53:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kurt.sys](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/kurt.sys/32/22516_2.png) [@kurt.sys](https://community.auth0.com/u/kurt.sys)\
**Post date:** [March 5, 2018, 1:53am UTC](https://community.auth0.com/t/valid-jwt-using-curl-not-when-using-node-js/9703/1 "2018-03-05T01:53:04Z")

</div>

I’m trying to get a valid JWT from a node.js application. I can make it work using cURL:

```auto
curl th0.com/oauth/token --header 'content-type: application/json' --data '{"client_id":<client_id>,"client_secret":<client-secret>,"audience":<audience>,"grant_type":"client_credentials"}'

```

The resulting JWT is valid using [jwt.io](http://jwt.io), and I can use it when I set it in the auth0 user mgmt APIv2.

When I do the same thing using node.js, I get a valid (and very similar as using cURL) token, but I get an `401 Unauthorized` when I try to use it:

```auto
let auth0Response =
                await fetch(`https://${process.env.AUTH0_DOMAIN}/oauth/token`,
                            {method: 'POST',
                             headers: {'content-type': 'application/json'},
                             body: JSON.stringify({"client_id":`${process.env.AUTH0_CLIENT_ID}`,
                                                   "client_secret":`${process.env.AUTH0_CLIENT_SECRET}`,
                                                   "audience":`https://${process.env.AUTH0_DOMAIN}/api/v2/`,
                                                   "grant_type":"client_credentials"})
                            })
                .then(response => response.json())
            console.log('token: ' + JSON.stringify(auth0Response))

```

This returns a valid JWT ([jwt.io](http://jwt.io)) with the right claims (the same ones as using cURL). However, I can’t seem to use this JWT to do any requests, nor programmatically, nor using the auth0 management APIv2 page.

I have no idea how to debug this, since the JWT is valid according to [jwt.io](http://jwt.io) (with the same claims as a working JWT), but apparently isn’t according to auth0.

What am I overlooking?

---

<div class="post-metadata">

**Author:** ![amin](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/amin/32/10144_2.png) [@amin](https://community.auth0.com/u/amin)\
**Post date:** [March 5, 2018, 5:17am UTC](https://community.auth0.com/t/valid-jwt-using-curl-not-when-using-node-js/9703/2 "2018-03-05T05:17:18Z")

</div>

Hi Kurt,

Do you see any errors in Dashboard Logs when using Node.js generated access\_token by any chance?

Regards,  
Amin

---

<div class="post-metadata">

**Author:** ![kurt.sys](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/kurt.sys/32/22516_2.png) [@kurt.sys](https://community.auth0.com/u/kurt.sys)\
**Post date:** [June 23, 2018, 3:41pm UTC](https://community.auth0.com/t/valid-jwt-using-curl-not-when-using-node-js/9703/3 "2018-06-23T15:41:27Z")

</div>

No, but it seems to be solved now.

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [July 25, 2019, 2:09pm UTC](https://community.auth0.com/t/valid-jwt-using-curl-not-when-using-node-js/9703/4 "2019-07-25T14:09:10Z")

</div>


