Type:
Module

HTTPAuth provides both basic and digest authentication.

To enable authentication for requests in WEBrick you will need a user database and an authenticator. To start, here's an Htpasswd database for use with a DigestAuth authenticator:

config = { :Realm => 'DigestAuth example realm' }

htpasswd = WEBrick::HTTPAuth::Htpasswd.new 'my_password_file'
htpasswd.auth_type = WEBrick::HTTPAuth::DigestAuth
htpasswd.set_passwd config[:Realm], 'username', 'password'
htpasswd.flush

The :Realm is used to provide different access to different groups across several resources on a server. Typically you'll need only one realm for a server.

This database can be used to create an authenticator:

config[:UserDB] = htpasswd

digest_auth = WEBrick::HTTPAuth::DigestAuth.new config

To authenticate a request call authenticate with a request and response object in a servlet:

def do_GET req, res
  @authenticator.authenticate req, res
end

For digest authentication the authenticator must not be created every request, it must be passed in as an option via WEBrick::HTTPServer#mount.

set_passwd
  • References/Ruby on Rails/Ruby/Classes/WEBrick/WEBrick::HTTPAuth/WEBrick::HTTPAuth::UserDB

set_passwd(realm, user, pass) Instance Public methods Sets a password in realm

2025-01-10 15:47:30
authenticate
  • References/Ruby on Rails/Ruby/Classes/WEBrick/WEBrick::HTTPAuth/WEBrick::HTTPAuth::BasicAuth

authenticate(req, res) Instance Public methods Authenticates a req

2025-01-10 15:47:30
proxy_basic_auth
  • References/Ruby on Rails/Ruby/Classes/WEBrick/WEBrick::HTTPAuth

proxy_basic_auth(req, res, realm) Instance Public methods Simple wrapper for

2025-01-10 15:47:30
set_passwd
  • References/Ruby on Rails/Ruby/Classes/WEBrick/WEBrick::HTTPAuth/WEBrick::HTTPAuth::Htpasswd

set_passwd(realm, user, pass) Instance Public methods Sets a password in the

2025-01-10 15:47:30
new
  • References/Ruby on Rails/Ruby/Classes/WEBrick/WEBrick::HTTPAuth/WEBrick::HTTPAuth::Htdigest

new(path) Class Public methods Open a digest password database at path

2025-01-10 15:47:30
delete_passwd
  • References/Ruby on Rails/Ruby/Classes/WEBrick/WEBrick::HTTPAuth/WEBrick::HTTPAuth::Htdigest

delete_passwd(realm, user) Instance Public methods Removes a password from the

2025-01-10 15:47:30
each
  • References/Ruby on Rails/Ruby/Classes/WEBrick/WEBrick::HTTPAuth/WEBrick::HTTPAuth::Htpasswd

each() Instance Public methods Iterate passwords in the database.

2025-01-10 15:47:30
challenge
  • References/Ruby on Rails/Ruby/Classes/WEBrick/WEBrick::HTTPAuth/WEBrick::HTTPAuth::BasicAuth

challenge(req, res) Instance Public methods Returns a challenge response which

2025-01-10 15:47:30
reload
  • References/Ruby on Rails/Ruby/Classes/WEBrick/WEBrick::HTTPAuth/WEBrick::HTTPAuth::Htpasswd

reload() Instance Public methods Reload passwords from the database

2025-01-10 15:47:30
reload
  • References/Ruby on Rails/Ruby/Classes/WEBrick/WEBrick::HTTPAuth/WEBrick::HTTPAuth::Htdigest

reload() Instance Public methods Reloads passwords from the database

2025-01-10 15:47:30