Module: WEBrick::HTTPAuth

Defined in:
lib/webrick/httpauth.rb,
lib/webrick/httpauth/userdb.rb,
lib/webrick/httpauth/htgroup.rb,
lib/webrick/httpauth/htdigest.rb,
lib/webrick/httpauth/htpasswd.rb,
lib/webrick/httpauth/basicauth.rb,
lib/webrick/httpauth/digestauth.rb,
lib/webrick/httpauth/authenticator.rb

Defined Under Namespace

Modules: Authenticator, ProxyAuthenticator, UserDB Classes: BasicAuth, DigestAuth, Htdigest, Htgroup, Htpasswd, ProxyBasicAuth, ProxyDigestAuth

Instance Method Summary collapse

Instance Method Details

#_basic_auth(req, res, realm, req_field, res_field, err_type, block) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/webrick/httpauth.rb', line 21

def _basic_auth(req, res, realm, req_field, res_field, err_type, block)
  user = pass = nil
  if /^Basic\s+(.*)/o =~ req[req_field]
    userpass = $1
    user, pass = userpass.unpack("m*")[0].split(":", 2)
  end
  if block.call(user, pass)
    req.user = user
    return
  end
  res[res_field] = "Basic realm=\"#{realm}\""
  raise err_type
end

#basic_auth(req, res, realm, &block) ⇒ Object



35
36
37
38
# File 'lib/webrick/httpauth.rb', line 35

def basic_auth(req, res, realm, &block)
  _basic_auth(req, res, realm, "Authorization", "WWW-Authenticate",
              HTTPStatus::Unauthorized, block)
end

#proxy_basic_auth(req, res, realm, &block) ⇒ Object



40
41
42
43
# File 'lib/webrick/httpauth.rb', line 40

def proxy_basic_auth(req, res, realm, &block)
  _basic_auth(req, res, realm, "Proxy-Authorization", "Proxy-Authenticate",
              HTTPStatus::ProxyAuthenticationRequired, block)
end