# How do I handle parsing JWT tokens using JWKS in Java (Scala)

**URL:** <https://community.auth0.com/t/how-do-i-handle-parsing-jwt-tokens-using-jwks-in-java-scala/87274>\
**Category:** Get Help\
**Tags:** java\
**Created:** [July 20, 2022, 1:54pm UTC](https://community.auth0.com/t/how-do-i-handle-parsing-jwt-tokens-using-jwks-in-java-scala/87274 "2022-07-20T13:54:28Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jgleason](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jgleason/32/25904_2.png) [@jgleason](https://community.auth0.com/u/jgleason)\
**Post date:** [July 20, 2022, 1:54pm UTC](https://community.auth0.com/t/how-do-i-handle-parsing-jwt-tokens-using-jwks-in-java-scala/87274/1 "2022-07-20T13:54:28Z")

</div>

I have the following in my express app

```auto
import bearer from "express-oauth2-jwt-bearer";

// Authorization middleware. When used, the Access Token must
// exist and be verified against the Auth0 JSON Web Key Set.
const checkJwt = bearer.auth({
  audience: "https://earth-838.me.dev/node",
  issuerBaseURL: "https://auth.me.dev",
});

const checkScopes = bearer.requiredScopes("access:node");

export {checkJwt, checkScopes};

```

I am looking for the equivilent in Scala and I came across this basic setup…

```auto
    val jwkStore = new JwkStore("{JWKS_FILE_HOST}")
    val keyProvider = new RSAKeyProvider {
      override def getPublicKeyById(s: String): RSAPublicKey = {

      }

      override def getPrivateKey: RSAPrivateKey = {

      }

      override def getPrivateKeyId: String = {

      }
    }

    try {
      val algorithm = Algorithm.RSA256(keyProvider)
      val verifier = JWT.require(algorithm).withIssuer("auth0").build //Reusable verifier instance
      val jwt = verifier.verify(token)
      System.out.println(jwt.getPayload)
    } catch {
      case exception: JWTVerificationException =>

      //Invalid signature/claims
    }

```

But I am not sure where JwksStore comes from and I am not sure how to handle things. Can someone provide an example?

---

<div class="post-metadata">

**Author:** ![josiah\_devizia](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/josiah_devizia/32/33352_2.png) [@josiah\_devizia](https://community.auth0.com/u/josiah_devizia)\
**Post date:** [July 20, 2022, 8:10pm UTC](https://community.auth0.com/t/how-do-i-handle-parsing-jwt-tokens-using-jwks-in-java-scala/87274/2 "2022-07-20T20:10:44Z")

</div>

The JWKs, (JSON Web Keys) are found at `/.well-known/jwks.json` of your auth0 tenant. They are public values and you do not need authorization to request them.

---

<div class="post-metadata">

**Author:** ![jgleason](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jgleason/32/25904_2.png) [@jgleason](https://community.auth0.com/u/jgleason)\
**Post date:** [July 20, 2022, 8:59pm UTC](https://community.auth0.com/t/how-do-i-handle-parsing-jwt-tokens-using-jwks-in-java-scala/87274/3 "2022-07-20T20:59:29Z")

</div>

Sorry I know what it is and where it is but I dont know how to reference it in the jwt module provided

---

<div class="post-metadata">

**Author:** ![cumaranathunga](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/cumaranathunga/32/50878_2.png) [@cumaranathunga](https://community.auth0.com/u/cumaranathunga)\
**Post date:** [April 8, 2024, 11:36am UTC](https://community.auth0.com/t/how-do-i-handle-parsing-jwt-tokens-using-jwks-in-java-scala/87274/4 "2024-04-08T11:36:22Z")

</div>

Hi can I know that is there a way to read the jks key store and read the public key from it and use that to verify the token instead of calling the endpoint and getting the public key?  
Thanks a lot

---

<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:** [April 8, 2024, 8:37pm UTC](https://community.auth0.com/t/how-do-i-handle-parsing-jwt-tokens-using-jwks-in-java-scala/87274/6 "2024-04-08T20:37:49Z")

</div>

Hey @cumaranathunga welcome to the community!

There isn’t a standard alternative method for fetching JWKS. The use of the [JWKS endpoint](https://auth0.com/docs/secure/tokens/json-web-tokens/json-web-key-sets) is the recommended and secure way to obtain the necessary keys for token validation. This approach ensures that the keys are always up-to-date and valid, aligning with best practices in OAuth 2.0 and OpenID Connect protocols.

---

<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:** [April 22, 2024, 8:38pm UTC](https://community.auth0.com/t/how-do-i-handle-parsing-jwt-tokens-using-jwks-in-java-scala/87274/7 "2024-04-22T20:38:14Z")

</div>

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