# JWT Verification in Java

**URL:** <https://devforum.okta.com/t/jwt-verification-in-java/7528>\
**Category:** Questions\
**Created:** [January 6, 2020, 1:54pm UTC](https://devforum.okta.com/t/jwt-verification-in-java/7528 "2020-01-06T13:54:49Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![WilliamNoad](https://avatars.discourse-cdn.com/v4/letter/w/dbc845/32.png) [@WilliamNoad](https://devforum.okta.com/u/WilliamNoad)\
**Post date:** [January 6, 2020, 1:54pm UTC](https://devforum.okta.com/t/jwt-verification-in-java/7528/1 "2020-01-06T13:54:49Z")

</div>

We’re having problems using the `okta-jwt-verifier-java` in our application, and need a little bit of guidance.

Our application is Spring Boot on Tomcat, providing a set of REST endpoints for a single-page Angular application. For (complicated internal business) reasons the Okta authentication/authorisation processes were retrofitted to the front-end late in the development process (part-way through UAT.) Redeveloping the existing code to leverage Spring Security is not an option, so we’re trying to validate the access token using the library.

The symptom is that the library is throwing various exceptions during the `decode` call.

- If the issuer is set to `https:// *******.okta-emea.com/oauth2/default/` the exception reports a 403 error on the `/oauth2/default/v1/keys` endpoint
- If the issuer is set to `https:// *******.okta-emea.com/oauth2/`, the library gets a 403 error requesting `/oauth2/oauth2/v1/keys`
- If the issuer is set to `https:// *******.okta-emea.com/` which matches the front-end’s configuration, we get a warning that the issuer should be of the form `https://{yourOktaDomain}/oauth2/qualifier`, followed by an illegal argument exception `A signing key must be specified if the specified JWT is digitally signed.`

The keys are available to us from the URL `https:// ******.okta-emea.com/oauth2/v1/keys`, so it looks as though we’re missing a trick in configuring the library.

If it’s relevant we’re using Okta for SSO, integrated with our Windows AD.

Has anyone else seen or solved this problem?

---

<div class="post-metadata">

**Author:** ![Govner](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/govner/32/1099_2.png) [@Govner](https://devforum.okta.com/u/Govner)\
**Post date:** [January 6, 2020, 2:28pm UTC](https://devforum.okta.com/t/jwt-verification-in-java/7528/2 "2020-01-06T14:28:45Z")

</div>

Remove the trailing slash and set to `https:// *******.okta-emea.com/oauth2/default`

---

<div class="post-metadata">

**Author:** ![WilliamNoad](https://avatars.discourse-cdn.com/v4/letter/w/dbc845/32.png) [@WilliamNoad](https://devforum.okta.com/u/WilliamNoad)\
**Post date:** [January 6, 2020, 2:40pm UTC](https://devforum.okta.com/t/jwt-verification-in-java/7528/3 "2020-01-06T14:40:12Z")

</div>

I tried that: I get the error `Failed to fetch keys`, exactly the same as in the first bullet point.

The keys are not available from that endpoint, only `/oauth2/v1/keys`.

---

<div class="post-metadata">

**Author:** ![vijet](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/vijet/32/245_2.png) [@vijet](https://devforum.okta.com/u/vijet)\
**Post date:** [January 6, 2020, 6:26pm UTC](https://devforum.okta.com/t/jwt-verification-in-java/7528/4 "2020-01-06T18:26:31Z")

</div>

Hi @WilliamNoad

Just to be clear here, are you protecting the REST endpoints on the spring application using the access token obtained by the front-end?  
If so, you will have to be aware of the following things -

The front-end config should have the ISSUER set to `https:// *******.okta-emea.com/oauth2/default`  
This is the default authorization server included in your okta org.  
You can verify it by logging in as admin to your org, and navigating to Security -\> API -\> Authorization Servers  
You should see something like this -

 ![auth-server](https://global.discourse-cdn.com/oktadev/original/2X/5/58dd2820311aa85f70374ddec0cea7bf1099b6de.jpeg)

If this is not available, you can create a new authorization server, and name it default (or any other name convenient)

You can check the config to use from this link as well - `https:// ******* -emea.com/oauth2/default/.well-known/oauth-authorization-server`

To clarify a few things, the endpoints that your application/backend should call should always be of the prefix `https:// ******* -emea.com/oauth2/default`.

`https:// ******.okta-emea.com/oauth2/v1/keys` contains the keys for the authorization server of your okta org i.e. it is the server that protects Okta’s endpoints.  
`https:// ******.okta-emea.com/oauth2/default/v1/keys` contains the keys for the authorization server for your application (created by okta for you) i.e. it is the server that protects your application endpoints.

I know it’s a bit confusing. Read this link for more details - [https://developer.okta.com/docs/concepts/auth-servers/](https://developer.okta.com/docs/concepts/auth-servers/)

Hope this helps.

---

<div class="post-metadata">

**Author:** ![bdemers](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/bdemers/32/23_2.png) [@bdemers](https://devforum.okta.com/u/bdemers)\
**Post date:** [January 9, 2020, 3:06pm UTC](https://devforum.okta.com/t/jwt-verification-in-java/7528/5 "2020-01-09T15:06:41Z")

</div>

Hi @WilliamNoad!

Try what @vijet suggested first, and if that doesn’t help contact support (or your sales rep) and make sure you have “API AM” enabled on the Org you are using for testing.

Keep us posted!

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/oktadev/original/1X/589c4c5f80de422d01f47cee7185a7fb8227835c.png) [@system](https://devforum.okta.com/u/system)\
**Post date:** [January 23, 2024, 7:55pm UTC](https://devforum.okta.com/t/jwt-verification-in-java/7528/6 "2024-01-23T19:55:19Z")

</div>

Closed on January 23, 2024, 7:55pm UTC

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