# How to verify that a JWT is legit?

**URL:** <https://community.auth0.com/t/how-to-verify-that-a-jwt-is-legit/105458>\
**Category:** JWT.io\
**Tags:** jwt, api, id\_token, authentication, auth0\
**Created:** [April 25, 2023, 12:19pm UTC](https://community.auth0.com/t/how-to-verify-that-a-jwt-is-legit/105458 "2023-04-25T12:19:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ilanoh](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@Ilanoh](https://community.auth0.com/u/Ilanoh)\
**Post date:** [April 25, 2023, 12:19pm UTC](https://community.auth0.com/t/how-to-verify-that-a-jwt-is-legit/105458/1 "2023-04-25T12:19:31Z")

</div>

Hello,

I receive an ID Token when a user login to the app.  
I want to check in my server that the JWT is valid.  
And then show to my user some specific datas that are not stored with auth0 from my server.

Is there a way to verify that the nonce in the JWT is the same as the nonce when auth0 created the JWT? If not how can I check I’m not victim of a replay attack? If yes how can I check?

How can I make sure that the token was signed by the private key associated with my app?

If someone create a fake JWT that decode to informations that are consistent with the payload. I can get tricked, I cannot use the payload to verify.

Also anyone can access my domain key set by checking

```auto
https://domain/.well-known/jwks.json

```

So the JWT counterfeiter can just verify that his fake JWT verifies with the public signature before sending it to my server.

So how do I verify that a JWT is legit when I receive one?

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [April 26, 2023, 2:37pm UTC](https://community.auth0.com/t/how-to-verify-that-a-jwt-is-legit/105458/3 "2023-04-26T14:37:43Z")

</div>

Hi @Ilanoh,

Thanks for the thorough questions.

> [@Ilanoh](#):
>
> Is there a way to verify that the nonce in the JWT is the same as the nonce when auth0 created the JWT?

What is the nonce you are referencing here? Do you have an example or the name of the claim you are looking at? If you’re talking about the nonce in the authorize request, you can use one of our SDKs to handle the transaction and you won’t have to handle the nonce at all.

> [@Ilanoh](#):
>
> If not how can I check I’m not victim of a replay attack? If yes how can I check?

This article shares some strategies for [preventing replay attacks](https://auth0.com/docs/secure/security-guidance/prevent-threats#replay-attacks).

> [@Ilanoh](#):
>
> How can I make sure that the token was signed by the private key associated with my app?

This is the purpose of the token signature. A token signature cannot be validated with the associated public key if it wasn’t signed by the private key. This is a fundamental function of JWTs.

> [@Ilanoh](#):
>
> If someone create a fake JWT that decode to informations that are consistent with the payload. I can get tricked, I cannot use the payload to verify.

You need to validate the signature before trusting the token.

> [@Ilanoh](#):
>
> Also anyone can access my domain key set by checking

Yes, this is an important feature of asymmetric encryption.

> [@Ilanoh](#):
>
> So the JWT counterfeiter can just verify that his fake JWT verifies with the public signature before sending it to my server.

This would require that they brute force the private key, and that isn’t going to happen in our current era of computing. This is fundamental of all cryptography.

> [@Ilanoh](#):
>
> So how do I verify that a JWT is legit when I receive one?

By validating the signature with the public key. Here’s some reading on it [Signing Algorithms](https://auth0.com/docs/get-started/applications/signing-algorithms).

---

<div class="post-metadata">

**Author:** ![Ilanoh](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@Ilanoh](https://community.auth0.com/u/Ilanoh)\
**Post date:** [April 27, 2023, 11:58am UTC](https://community.auth0.com/t/how-to-verify-that-a-jwt-is-legit/105458/4 "2023-04-27T11:58:00Z")

</div>

Thanks for the answers, i recently learned about asymmetric, i was more used to hashcash, i try to verify the token in apex salesforce, do you have any ressources on this? because in apex there isn’t much documentation and no libraries or sdk.

there is a function like this:

```auto
Crypto.verify('RSA-SHA256', payload, signature, publickey)

```

But it doesn’t work, how would you do?

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [May 1, 2023, 1:24pm UTC](https://community.auth0.com/t/how-to-verify-that-a-jwt-is-legit/105458/5 "2023-05-01T13:24:33Z")

</div>

That looks like the correct approach to me. What happens when you try this out? Do you see any errors?

Additionally, you can provide a sample token, and how you use the inputs `payload`, `signature`, `publickey`.

You can also DM me if the data is private.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [June 21, 2023, 6:35pm UTC](https://community.auth0.com/t/how-to-verify-that-a-jwt-is-legit/105458/6 "2023-06-21T18:35:59Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
