Class: Aker::Rack::Failure

Inherits:
Object
  • Object
show all
Includes:
EnvironmentHelper
Defined in:
lib/aker/rack/failure.rb

Overview

The Rack endpoint which handles authentication failures.

See Also:

Instance Method Summary (collapse)

Methods included from EnvironmentHelper

#authority, #configuration, #interactive?

Instance Method Details

- (Array) call(env)

Receives the rack environment in case of a failure and renders a response based on the interactiveness of the request and the nature of the configured modes.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/aker/rack/failure.rb', line 22

def call(env)
  conf = configuration(env)
  if (env)
    if interactive?(env)
      ::Warden::Strategies[conf.ui_mode].new(env).on_ui_failure.finish
    else
      headers = {}
      headers["WWW-Authenticate"] =
        conf.api_modes.collect { |mode_key|
        ::Warden::Strategies[mode_key].new(env).challenge
      }.join("\n")
      headers["Content-Type"] = "text/plain"
      [401, headers, ["Authentication required"]]
    end
  else
    log_authorization_failure(env)
    msg = "#{user(env).username} may not use this page."
    Rack::Response.
      new("<html><head><title>Authorization denied</title></head><body>#{msg}</body></html>",
          403,
          "Content-Type" => "text/html").finish
  end
end