Class: JWT::JWK::KeyFinder
- Inherits:
-
Object
- Object
- JWT::JWK::KeyFinder
- Defined in:
- lib/jwt/jwk/key_finder.rb
Overview
JSON Web Key keyfinder To find the key for a given kid
Instance Method Summary collapse
-
#call(token) ⇒ Object
Returns the key for the given token.
-
#initialize(options) ⇒ KeyFinder
constructor
Initializes a new KeyFinder instance.
-
#key_for(kid) ⇒ Object
Returns the verification key for the given kid.
Constructor Details
#initialize(options) ⇒ KeyFinder
Initializes a new KeyFinder instance.
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/jwt/jwk/key_finder.rb', line 12 def initialize() @allow_nil_kid = [:allow_nil_kid] jwks_or_loader = [:jwks] @jwks_loader = if jwks_or_loader.respond_to?(:call) jwks_or_loader else ->() { jwks_or_loader } end end |
Instance Method Details
#call(token) ⇒ Object
Returns the key for the given token
39 40 41 |
# File 'lib/jwt/jwk/key_finder.rb', line 39 def call(token) key_for(token.header['kid']) end |
#key_for(kid) ⇒ Object
Returns the verification key for the given kid
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/jwt/jwk/key_finder.rb', line 25 def key_for(kid) raise ::JWT::DecodeError, 'No key id (kid) found from token headers' unless kid || @allow_nil_kid raise ::JWT::DecodeError, 'Invalid type for kid header parameter' unless kid.nil? || kid.is_a?(String) jwk = resolve_key(kid) raise ::JWT::DecodeError, 'No keys found in jwks' unless @jwks.any? raise ::JWT::DecodeError, "Could not find public key for kid #{kid}" unless jwk jwk.verify_key end |