# Verifying JWT in browser using public key

**URL:** <https://community.auth0.com/t/verifying-jwt-in-browser-using-public-key/83329>\
**Category:** JWT.io\
**Created:** [May 12, 2022, 10:52am UTC](https://community.auth0.com/t/verifying-jwt-in-browser-using-public-key/83329 "2022-05-12T10:52:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ScottKnick](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/scottknick/32/27810_2.png) [@ScottKnick](https://community.auth0.com/u/ScottKnick)\
**Post date:** [May 12, 2022, 10:52am UTC](https://community.auth0.com/t/verifying-jwt-in-browser-using-public-key/83329/1 "2022-05-12T10:52:49Z")

</div>

I’m near certain a hundred different versions of this question must have been asked by now, but I want to explain my scenario specifically because security is easy to mess up.

In my case, my site’s server is providing an endpoint from which a client can request an access token, which is really a JWT. The client provides their username and password and the server looks to see if their account is valid and if so provides a JWT that is signed using the server’s private key. The JWT also contains a claim for what “tier” of access they have (i.e., standard, premium, or admin).

What I want to do is be able to validate that the provided JWT is the one provided by the server. Specifically, I want to do this because I intend to save the JWT in local storage in the browser to avoid the authentication process again, and when I read the JWT from local storage, I want to validate that it’s not been tampered with as it contains claims that will change the site behavior client-side.

To allow for this validation, I was going to provide an endpoint on the server that returns the PEM-encoded public certificate of the site. The client could then request this and load the public key to validate the JWT.

So my question is: Is this a proper way to do this? Is it leaving the possibility for a malicious user to circumvent the JWT validation in some way?

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [September 27, 2022, 12:04am UTC](https://community.auth0.com/t/verifying-jwt-in-browser-using-public-key/83329/2 "2022-09-27T00:04:02Z")

</div>

Hey @ScottKnick!

I apologize for the delayed response, but just wanted to circle back on this one - Did you end up implementing something like this?

> [@ScottKnick](#):
>
> In my case, my site’s server is providing an endpoint from which a client can request an access token, which is really a JWT. The client provides their username and password and the server looks to see if their account is valid and if so provides a JWT that is signed using the server’s private key. The JWT also contains a claim for what “tier” of access they have (i.e., standard, premium, or admin).
> 
> What I want to do is be able to validate that the provided JWT is the one provided by the server. Specifically, I want to do this because I intend to save the JWT in local storage in the browser to avoid the authentication process again, and when I read the JWT from local storage, I want to validate that it’s not been tampered with as it contains claims that will change the site behavior client-side.

I’m not entirely clear on your case - Is the access token eventually consumed by an API? Access tokens are typically [validated/verified by an API](https://auth0.com/docs/secure/tokens/access-tokens/validate-access-tokens) and most often using a 3rd party libraries (which use the [jwks](https://auth0.com/docs/secure/tokens/json-web-tokens/json-web-key-sets) endpoint). ID tokens are the only tokens that should be consumed client-side.

One concern is with storing tokens in local storage as this opens them up to XSS, some more on that [here](https://auth0.com/docs/secure/security-guidance/data-security/token-storage#browser-local-storage-scenarios). Here’s a helpful blog post on [browser storage](https://auth0.com/blog/secure-browser-storage-the-facts/).

I like to link to our Architecture Scenario documentation any chance I get - There’s some really useful information on what common architectures look like:

> **[Architecture Scenarios](https://auth0.com/docs/get-started/architecture-scenarios)**
>
> Learn about common Auth0 architecture scenarios that you can use to solve your authorization and authentication needs.

Hope this helps!

---

<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:** [December 22, 2022, 12:24am UTC](https://community.auth0.com/t/verifying-jwt-in-browser-using-public-key/83329/4 "2022-12-22T00:24:43Z")

</div>

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