Meet SourceLevel, your automatic code reviewer

SourceLevel does continuous static analysis of your GitHub repositories and delivers it straight to your Pull Requests

Get started for free

Great, lib/jwt/jwk/key_finder.rb does not have any issues!

Go to line 1
# frozen_string_literal: true
Go to line 3
module JWT
Go to line 4
  module JWK
Go to line 5
    class KeyFinder
Go to line 6
      def initialize(options)
Go to line 7
        jwks_or_loader = options[:jwks]
Go to line 8
        @jwks          = jwks_or_loader if jwks_or_loader.is_a?(Hash)
Go to line 9
        @jwk_loader    = jwks_or_loader if jwks_or_loader.respond_to?(:call)
Go to line 12
      def key_for(kid)
Go to line 13
        raise ::JWT::DecodeError, 'No key id (kid) found from token headers' unless kid
Go to line 15
        jwk = resolve_key(kid)
Go to line 17
        raise ::JWT::DecodeError, 'No keys found in jwks' if jwks_keys.empty?
Go to line 18
        raise ::JWT::DecodeError, "Could not find public key for kid #{kid}" unless jwk
Go to line 20
        ::JWT::JWK.import(jwk).keypair
Go to line 25
      def resolve_key(kid)
Go to line 26
        jwk = find_key(kid)
Go to line 28
        return jwk if jwk
Go to line 30
        if reloadable?
Go to line 31
          load_keys(invalidate: true)
Go to line 32
          return find_key(kid)
Go to line 39
        return @jwks if @jwks
Go to line 41
        load_keys
Go to line 45
      def load_keys(opts = {})
Go to line 46
        @jwks = @jwk_loader.call(opts)
Go to line 49
      def jwks_keys
Go to line 50
        Array(jwks[:keys] || jwks['keys'])
Go to line 53
      def find_key(kid)
Go to line 54
        jwks_keys.find { |key| (key[:kid] || key['kid']) == kid }
Go to line 57
      def reloadable?
Go to line 58
        @jwk_loader