Class: Himari::Services::JwksEndpoint::Handler

Inherits:
Object
  • Object
show all
Defined in:
lib/himari/services/jwks_endpoint.rb

Defined Under Namespace

Classes: InvalidToken

Instance Method Summary collapse

Constructor Details

#initialize(signing_key_provider:, env:) ⇒ Handler

Returns a new instance of Handler.



20
21
22
23
# File 'lib/himari/services/jwks_endpoint.rb', line 20

def initialize(signing_key_provider:, env:)
  @signing_key_provider = signing_key_provider
  @env = env
end

Instance Method Details

#responseObject



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/himari/services/jwks_endpoint.rb', line 25

def response
  # https://www.rfc-editor.org/rfc/rfc7517#section-5
  return [404, {'Content-Type' => 'application/json'}, ['{"error": "not_found"}']] unless @env['REQUEST_METHOD'] == 'GET'

  signing_keys = @signing_key_provider.collect()

  [
    200,
    {'Content-Type' => 'application/json; charset=utf-8'},
    [JSON.pretty_generate(keys: signing_keys.map(&:as_jwk)), "\n"],
  ]
end