Module: JWT::JWK

Defined in:
lib/jwt/jwk.rb,
lib/jwt/jwk/ec.rb,
lib/jwt/jwk/rsa.rb,
lib/jwt/jwk/hmac.rb,
lib/jwt/jwk/key_base.rb,
lib/jwt/jwk/key_finder.rb

Defined Under Namespace

Classes: EC, HMAC, KeyBase, KeyFinder, RSA

Class Method Summary collapse

Class Method Details

.classesObject


23
24
25
26
# File 'lib/jwt/jwk.rb', line 23

def classes
  @mappings = nil # reset the cached mappings
  @classes ||= []
end

.create_from(keypair, kid = nil) ⇒ Object Also known as: new


17
18
19
20
21
# File 'lib/jwt/jwk.rb', line 17

def create_from(keypair, kid = nil)
  mappings.fetch(keypair.class) do |klass|
    raise JWT::JWKError, "Cannot create JWK from a #{klass.name}"
  end.new(keypair, kid)
end

.import(jwk_data) ⇒ Object

Raises:


8
9
10
11
12
13
14
15
# File 'lib/jwt/jwk.rb', line 8

def import(jwk_data)
  jwk_kty = jwk_data[:kty] || jwk_data['kty']
  raise JWT::JWKError, 'Key type (kty) not provided' unless jwk_kty

  mappings.fetch(jwk_kty.to_s) do |kty|
    raise JWT::JWKError, "Key type #{kty} not supported"
  end.import(jwk_data)
end