jwt exp claim is type string #464
Replies: 4 comments
-
Can you reproduce this without rodauth-rails? If so, please provide a minimal self-contained reproducible example and I will look into it. |
Beta Was this translation helpful? Give feedback.
-
Thanks for your fast response Jeremy. The issue is not with rodauth. Here's an example of a decoded jwt when using just rodauth:
And a pry session inspecting
I noticed that the rodauth: rodauth-rails: I'm going to create a minimal rails app with rodauth-rails tonight to see if I can recreate my issue. I don't want to use my current rails app because it has a number of gems installed. I'll report back. Thanks again! |
Beta Was this translation helpful? Give feedback.
-
I found the issue. It has nothing to do with rodauth or rodauth-rails. The issue lies with setting Rails’ ActiveSupport::Duration (30.minutes) converts durations into objects that, when serialized, seems to produce strings instead of integers in JSON contexts.
To test this: rails console
duration = 30.minutes
puts duration.class
=> ActiveSupport::Duration
require 'json'
duration = 30.minutes
json_output = JSON.dump({ duration: duration })
puts json_output
=> {"duration":"1800.0"} Thanks again for getting back to me so quickly, Jeremy! |
Beta Was this translation helpful? Give feedback.
-
I forgot to say, the fix is to just call
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
The jwt exp claim is type string when it should be an integer:
See https://www.rfc-editor.org/rfc/rfc7519.html#section-4.1.4
Here's an example:
{
"exp": "1736872433",
"iat": 1736870633,
"nbf": 1736870628,
"user": {
"id": "a0dffd14-a3c1-4a73-947c-9373440cf57f",
"name": "holden",
"status": 2,
"loggedIn": false,
"role": "user",
"authenticatedBy": null
}
}
In searching for a way to "fix" this I've seen several other people post decoded rodauth JWTs where the exp value type is also string (they were not posting because of this issue.)
What's strange, is I've confirmed
exp
is being set as an integer:But later, when I decode it, it's string:
I need a "fix" for this because Jose says the jwt is invalid due to this issue. I can't use jsonwebtoken for various reasons.
Any insight into this issue would be greatly appreciated!
Oh, I'm using the
rodauth-rails
gem.Thanks for creating such a wonderful authentication gem!
Beta Was this translation helpful? Give feedback.
All reactions