Class: WEBrick::HTTPAuth::AskForUserName

Inherits:
Object
  • Object
show all
Includes:
Authenticator, SoksUserCookie
Defined in:
lib/authenticators.rb

Constant Summary collapse

AuthScheme =
"Basic"

Instance Method Summary collapse

Methods included from SoksUserCookie

#add_cookie, #username_from_cookie

Constructor Details

#initialize(realm = "editing") ⇒ AskForUserName

Returns a new instance of AskForUserName.



50
51
52
53
54
# File 'lib/authenticators.rb', line 50

def initialize( realm = "editing" )
				config = { :UserDB => "nodb" , :Realm => realm }
   	check_init(config)
				@config = Config::BasicAuth.dup.update(config)
end

Instance Method Details

#authenticate(req, res) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/authenticators.rb', line 56

def authenticate(req, res)
  unless basic_credentials = check_scheme(req)
    challenge(req, res)
  end
  userid, password = Base64.decode64(basic_credentials).split(":", 2) 
  if userid.empty?
    error("user id was not given.")
    challenge(req, res)
  end
  info("%s: authentication succeeded.", userid)
  req.user = userid
  add_cookie(req,res)
  userid
end

#challenge(req, res) ⇒ Object

Raises:

  • (@auth_exception)


71
72
73
74
# File 'lib/authenticators.rb', line 71

def challenge(req, res)
  res[@response_field] = "#{@auth_scheme} realm=\"#{@realm}\""
  raise @auth_exception
end