Module: Htpasswd::Auths

Defined in:
lib/htpasswd/auths/base.rb,
lib/htpasswd/auths/basic.rb,
lib/htpasswd/auths/digest.rb

Defined Under Namespace

Classes: Base, Basic, Digest

Constant Summary collapse

@@schemas =
{}

Class Method Summary collapse

Class Method Details

.[](auth_scheme) ⇒ Object



6
7
8
# File 'lib/htpasswd/auths/base.rb', line 6

def [](auth_scheme)
  @@schemas[auth_scheme.to_s.classify]
end

.default_realmObject



38
39
40
# File 'lib/htpasswd/auths/base.rb', line 38

def default_realm
  "Authorization"
end

.extract_header(hash) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/htpasswd/auths/base.rb', line 29

def extract_header(hash)
  [
   'X-HTTP_AUTHORIZATION',          # for Apache/mod_rewrite
   'REDIRECT_X_HTTP_AUTHORIZATION', # for Apache2/mod_rewrite
   'Authorization',                 # for Apace/mod_fastcgi with -pass-header Authorization 
   'HTTP_AUTHORIZATION',            # this is the regular location 
  ].map{|name| hash[name]}.compact.first
end

.instantiate(header) ⇒ Object

Raises:



21
22
23
24
25
26
27
# File 'lib/htpasswd/auths/base.rb', line 21

def instantiate(header)
  raise HeaderNotFound if header.blank?
  ActionController::Base.logger.debug "Htpasswd accepts authorization header: '#{header}'"
  type, data = header.to_s.split(' ', 2)
  klass = self[type] or raise UnknownSchemeError, type
  klass.parse(data)
end

.scheme(controller) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/htpasswd/auths/base.rb', line 10

def scheme(controller)
  case controller
  when ActionController::Base
    returning authorization = instantiate(extract_header(controller.request.env)) do
      authorization.set_controller(controller)
    end
  else
    instantiate(controller.to_s)
  end
end