Module: Mpp::Server::Decorator

Extended by:
T::Sig
Defined in:
lib/mpp/server/decorator.rb

Class Method Summary collapse

Class Method Details

.make_challenge_response(challenge, realm) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/mpp/server/decorator.rb', line 15

def make_challenge_response(challenge, realm)
  error = Mpp::PaymentRequiredError.new(realm: realm, description: challenge.description)
  body = JSON.generate(error.to_problem_details(challenge_id: challenge.id))
  headers = {
    "WWW-Authenticate" => challenge.to_www_authenticate(realm),
    "Cache-Control" => "no-store",
    "Content-Type" => "application/problem+json"
  }
  {
    "_mpp_challenge" => true,
    "status" => 402,
    "headers" => headers,
    "body" => body
  }
end