module JWT::JWK

Public Class Methods

classes() click to toggle source
# File lib/jwt/jwk.rb, line 24
def classes
  @mappings = nil # reset the cached mappings
  @classes ||= []
end
create_from(key, params = nil, options = {}) click to toggle source
# File lib/jwt/jwk.rb, line 9
def create_from(key, params = nil, options = {})
  if key.is_a?(Hash)
    jwk_kty = key[:kty] || key['kty']
    raise JWT::JWKError, 'Key type (kty) not provided' unless jwk_kty

    return mappings.fetch(jwk_kty.to_s) do |kty|
      raise JWT::JWKError, "Key type #{kty} not supported"
    end.new(key, params, options)
  end

  mappings.fetch(key.class) do |klass|
    raise JWT::JWKError, "Cannot create JWK from a #{klass.name}"
  end.new(key, params, options)
end
Also aliased as: new, import
import(key, params = nil, options = {})
Alias for: create_from
new(key, params = nil, options = {})
Alias for: create_from

Private Class Methods

generate_mappings() click to toggle source
# File lib/jwt/jwk.rb, line 38
def generate_mappings
  classes.each_with_object({}) do |klass, hash|
    next unless klass.const_defined?('KTYS')

    Array(klass::KTYS).each do |kty|
      hash[kty] = klass
    end
  end
end
mappings() click to toggle source
# File lib/jwt/jwk.rb, line 34
def mappings
  @mappings ||= generate_mappings
end