Class: WEBrick::HTTPAuth::AskForUserName
- Inherits:
-
Object
- Object
- WEBrick::HTTPAuth::AskForUserName
- Includes:
- Authenticator, SoksUserCookie
- Defined in:
- lib/authenticators.rb
Constant Summary collapse
- AuthScheme =
"Basic"
Instance Method Summary collapse
- #authenticate(req, res) ⇒ Object
- #challenge(req, res) ⇒ Object
-
#initialize(realm = "editing") ⇒ AskForUserName
constructor
A new instance of AskForUserName.
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 (req,res) userid end |
#challenge(req, res) ⇒ Object
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 |