Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upverify_iss: true is raising JWT::DecodeError instead of JWT::InvalidIssuerError #170
Comments
Actually, changing the |
I wrote a spec for the issue: require 'spec_helper'
require 'jwt'
require 'jwt/decode'
describe JWT do
it 'should throw a JWT::InvalidIssuerError' do
payload = {
"exp": Time.now.to_i + 120,
"iat": Time.now.to_i - 120,
"iss": "wrong",
"scopes": [
"add_money",
"remove_money",
"view_money"
],
"user": {
"username": "scalp"
}
}
token = JWT.encode payload, 'secret', 'HS256'
expect do
JWT.decode token, 'secret', true, { algorithm: 'HS256', iss: 'test', verify_iss: true }
end.to raise_error JWT::InvalidIssuerError
end
end I get the correct error. Which version are you using? |
Just change your rescue JWT::ExpiredSignature
[403, { 'Content-Type' => 'text/plain' }, ['The token has expired.']]
rescue JWT::InvalidIssuerError
[403, { 'Content-Type' => 'text/plain' }, ['The token does not have a valid issuer.']]
rescue JWT::InvalidIatError
[403, { 'Content-Type' => 'text/plain' }, ['The token does not have a valid "issued at" time.']]
rescue JWT::DecodeError
[401, { 'Content-Type' => 'text/plain' }, ['A token must be passed.']]
end All JWT errors derive from |
@excpt I see the issue now, thanks a lot for the help and sorry for opening this |
Hi! i removed the slice on: and works for me :) |
When trying to encode/decode payloads, if I change the
iss
value with something else and settingverify_iss: true
, I'm getting the wrong kind of error:Now using jwt.io with the secret
secret
:If I change
iss
in the payload towhatever
for example, I would expect to seeJWT::InvalidIssuerError
happening but it doesn't appear to be the case in my code.With
iss
being set tosecret
in the payload:With
iss
being set towhatever
in the payload:With my code, I would have expected to see
'The token does not have a valid issuer.'
.Any idea ?
Thanks in advance!