---
title: "Discussion on \"Verifying JWTs with JWKS in Ruby\" | Hashnode"
description: "Discussion on \"Verifying JWTs with JWKS in Ruby\". How to use JWKS to verify your JWTs, and edgecases"
url: "https://hashnode.com/posts/verifying-jwts-with-jwks-in-ruby/60601e0238b0e14f092a32cc"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Verifying JWTs with JWKS in Ruby](https://blog.unathichonco.com/verifying-jwts-with-jwks-in-ruby?utm_source=hashnode&utm_medium=feed)

How to use JWKS to verify your JWTs, and edgecases

Mar 28, 2021 · 6 min read · blog.unathichonco.com  
Updated Apr 14, 2021  
Read the article

-   [#ruby](https://hashnode.com/tag/ruby)
-   [#ruby-on-rails](https://hashnode.com/tag/ruby-on-rails)
-   [#rails](https://hashnode.com/tag/rails)
-   [#jwt](https://hashnode.com/tag/jwt)
-   [#security](https://hashnode.com/tag/security)

## Written by

[Unathi Chonco](https://hashnode.com/@unathi)

@unathi · Amsterdam

  
[View profile](https://hashnode.com/@unathi)

Full Stack Engineer WeTransfer

Full Stack Engineer @ WeTranfer. Ruby on Rails enthusiast. Building beautifully obvious products, and the technology that powers them.

## Responses 1

Markdown supported · ⌘↵ to post

[Robert Pankowecki](https://hashnode.com/@robertpank)

[Aug 31, 2021](https://hashnode.com/posts/verifying-jwts-with-jwks-in-ruby/60601e0238b0e14f092a32cc/comment/612df7e64e9d8114f8adde07)

Using

```
force: true, skip_nil: true
```

does not work the way you described it in:

> Our #fetch\_jwks method only returns the JSON response if the request was successful, and nil otherwise. Meaning we can cater for any failed response by leaving the current value in the cache, so we always have the latest successful response we've received.

The cache will be cleared even if the response is not successful and fetch\_jwks returns nil.

```
Rails.cache.fetch("JWKS_CACHE_KEY", force: true, skip_nil: true) do
  Time.now.to_s  
end  
=> "2021-08-31 11:22:32 +0200"

Rails.cache.fetch("JWKS_CACHE_KEY", force: true, skip_nil: true) do
  nil  
end  
=> nil

Rails.cache.fetch("JWKS_CACHE_KEY")
=> nil
```

[Unathi Chonco](https://hashnode.com/@unathi)

[Aug 31, 2021](https://hashnode.com/posts/verifying-jwts-with-jwks-in-ruby/60601e0238b0e14f092a32cc/comment/612df7e64e9d8114f8adde07#reply-612e26904e9d8114f8ade7ec)

[Robert Pankowecki](https://hashnode.com/@robertpank) Nice catch. It looks like you're correct. An oversight while writing this. The issue here is using `force: true` and `skip_nil: true` at the same time. `force` is always going to force a cache write. So actually using them together would require splitting up the logic.

Thanks for pointing this out
