Skip to content

Commit

Permalink
verify takes 2 params, second being payload
Browse files Browse the repository at this point in the history
  • Loading branch information
ab320012 committed Sep 19, 2017
1 parent b9b220a commit e348ee3
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 e348ee3

Please sign in to comment.