Skip to content

Commit

Permalink
Merge pull request #238 from ab320012/add-payload-to-verify-jti
Browse files Browse the repository at this point in the history
verify takes 2 params, second being payload closes: #207
  • Loading branch information
excpt authored Oct 5, 2017
2 parents f943b9d + e348ee3 commit fd1f86c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/jwt/verify.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ def verify_jti
jti = @payload['jti']

if options_verify_jti.respond_to?(:call)
raise(JWT::InvalidJtiError, 'Invalid jti') unless options_verify_jti.call(jti)
verified = options_verify_jti.arity == 2 ? options_verify_jti.call(jti, @payload) : options_verify_jti.call(jti)
raise(JWT::InvalidJtiError, 'Invalid jti') unless verified
elsif jti.to_s.strip.empty?
raise(JWT::InvalidJtiError, 'Missing jti')
end
Expand Down
13 changes: 13 additions & 0 deletions spec/jwt/verify_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,19 @@ module JWT
it 'true proc should not raise JWT::InvalidJtiError' do
Verify.verify_jti(payload, options.merge(verify_jti: ->(_jti) { true }))
end

it 'it should not throw arguement error with 2 args' do
expect do
Verify.verify_jti(payload, options.merge(verify_jti: ->(_jti, pl) {
true
}))
end.to_not raise_error
end
it 'should have payload as second param in proc' do
Verify.verify_jti(payload, options.merge(verify_jti: ->(_jti, pl) {
expect(pl).to eq(payload)
}))
end
end

context '.verify_not_before(payload, options)' do
Expand Down

0 comments on commit fd1f86c

Please sign in to comment.