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:

1
2
3
4
5
6
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:

1
2
3
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:

1
2
3
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.

make_passwd
  • References/Ruby on Rails/Ruby/Classes/WEBrick/WEBrick::HTTPAuth/WEBrick::HTTPAuth::DigestAuth

make_passwd(realm, user, pass) Class Public methods Used by

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

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

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

members(group) Instance Public methods Retrieve the list of members from

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

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::Htgroup

new(path) Class Public methods Open a group database at path

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

get_passwd(realm, user, reload_db) Instance Public methods Retrieves a password

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

make_passwd(realm, user, pass) Class Public methods Used by

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

get_passwd(realm, user, reload_db=false) Instance Public methods Retrieves a

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

new(config, default=Config::DigestAuth) Class Public methods Creates a new

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

flush(output=nil) Instance Public methods Flush the password database. If output

2025-01-10 15:47:30