# Failed to fetch public keys to validate JWT

**URL:** <https://community.auth0.com/t/failed-to-fetch-public-keys-to-validate-jwt/93127>\
**Category:** Get Help\
**Tags:** jwt, api\
**Created:** [October 26, 2022, 10:10am UTC](https://community.auth0.com/t/failed-to-fetch-public-keys-to-validate-jwt/93127 "2022-10-26T10:10:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rkrishna](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rkrishna/32/15790_2.png) [@rkrishna](https://community.auth0.com/u/rkrishna)\
**Post date:** [October 26, 2022, 10:10am UTC](https://community.auth0.com/t/failed-to-fetch-public-keys-to-validate-jwt/93127/1 "2022-10-26T10:10:45Z")

</div>

We have implemented [Secure your API using Spring Security 5 and Auth0](https://auth0.com/docs/quickstart/backend/java-spring-security5/interactive). But sometimes when we try to deploy the API service or Server Machine restarts, the API Service is failing to deploy because the service is not able to fetch Public Keys using the issue URI and below is the exception we get to see.

```auto
org.springframework.security.authentication.AuthenticationServiceException: An error occurred while attempting to decode the Jwt: Couldn't retrieve remote JWK set: org.springframework.web.client.UnknownHttpStatusCodeException: 530 Server Error: "Internal Edge Error"

```

The error could be Auth0 returning 503 status code with error “Internal Edge Error” instead returning public keys to validate the JWT.

How to avoid this?

---

<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:** [October 28, 2022, 5:27pm UTC](https://community.auth0.com/t/failed-to-fetch-public-keys-to-validate-jwt/93127/3 "2022-10-28T17:27:18Z")

</div>

Hi @rkrishna,

You can cache the JWKs locally and only update when they are expired/rotated. This should help to mitigate the issue.

---

<div class="post-metadata">

**Author:** ![rkrishna](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rkrishna/32/15790_2.png) [@rkrishna](https://community.auth0.com/u/rkrishna)\
**Post date:** [October 28, 2022, 5:40pm UTC](https://community.auth0.com/t/failed-to-fetch-public-keys-to-validate-jwt/93127/4 "2022-10-28T17:40:53Z")

</div>

Hi @dan.woda,

Thanks for the hint.

But, it was managed by

```auto
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-oauth2-resource-server</artifactId>
    </dependency>

```

and have no control over it.

---

<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:** [November 14, 2024, 12:31am UTC](https://community.auth0.com/t/failed-to-fetch-public-keys-to-validate-jwt/93127/5 "2024-11-14T00:31:37Z")

</div>

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