Skip to content

Commit

Permalink
Merge pull request #109 from kjwierenga/feature/fix/incorrect-iat-exa…
Browse files Browse the repository at this point in the history
…mples

Fix incorrect `iat` examples
  • Loading branch information
excpt committed Oct 9, 2015
2 parents 4630752 + 8a0a18b commit 9e58061
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ token = JWT.encode jti_payload, hmac_secret, 'HS256'

begin
# Add jti and iat to the validation to check if the token has been manipulated
decoded_token = JWT.decode token, hmac_secret, true, { 'iat' => iat, 'jti' => jti, :verify_jti => true, :algorithm => 'HS256' }
decoded_token = JWT.decode token, hmac_secret, true, { 'jti' => jti, :verify_jti => true, :algorithm => 'HS256' }
# Check if the JTI has already been used
rescue JWT::InvalidJtiError
# Handle invalid token, e.g. logout user or deny access
Expand Down
6 changes: 3 additions & 3 deletions spec/jwt_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,15 @@
example_payload = { 'hello' => 'world', 'iat' => 1_425_917_209 }
example_secret = 'secret'
example_jwt = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJoZWxsbyI6IndvcmxkIiwiaWF0IjoxNDI1OTE3MjA5fQ.m4F-Ugo7aLnLunBBO3BeDidyWMx8T9eoJz6FW2rgQhU'
decoded_payload = JWT.decode(example_jwt, example_secret, true, iat: true)
decoded_payload = JWT.decode(example_jwt, example_secret, true)
expect(decoded_payload).to include(example_payload)
end

it 'raises decode exception when iat is invalid' do
# example_payload = {'hello' => 'world', 'iat' => 'abc'}
# example_payload = {'hello' => 'world', 'iat' => '1425917209'}
example_secret = 'secret'
example_jwt = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJoZWxsbyI6IndvcmxkIiwiaWF0IjoiMTQyNTkxNzIwOSJ9.Mn_vk61xWjIhbXFqAB0nFmNkDiCmfzUgl_LaCKRT6S8'
expect { JWT.decode(example_jwt, example_secret, true, verify_iat: true, 'iat' => 1_425_917_209) }.to raise_error(JWT::InvalidIatError)
expect { JWT.decode(example_jwt, example_secret, true, verify_iat: true) }.to raise_error(JWT::InvalidIatError)
end

it 'raises decode exception when iat is in the future' do
Expand Down

0 comments on commit 9e58061

Please sign in to comment.