Module: WEBrick::HTTPAuth (Ruby 2.7.2)
Description: Module : WEBrick::HTTPAuth - Ruby 2.7.2

### Home Classes Methods

### In Files

- webrick/httpauth.rb
- webrick/httpauth/authenticator.rb
- webrick/httpauth/basicauth.rb
- webrick/httpauth/digestauth.rb
- webrick/httpauth/htdigest.rb
- webrick/httpauth/htgroup.rb
- webrick/httpauth/htpasswd.rb
- webrick/httpauth/userdb.rb

### Namespace

- MODULE WEBrick::HTTPAuth::Authenticator
- MODULE WEBrick::HTTPAuth::ProxyAuthenticator
- MODULE WEBrick::HTTPAuth::UserDB
- CLASS WEBrick::HTTPAuth::BasicAuth
- CLASS WEBrick::HTTPAuth::DigestAuth
- CLASS WEBrick::HTTPAuth::Htdigest
- CLASS WEBrick::HTTPAuth::Htgroup
- CLASS WEBrick::HTTPAuth::Htpasswd
- CLASS WEBrick::HTTPAuth::ProxyBasicAuth
- CLASS WEBrick::HTTPAuth::ProxyDigestAuth

### Methods

- #basic_auth
- #proxy_basic_auth

### Class/Module Index

Quicksearch

- Dir
- Errno
- Errno::ECONNABORTED
- Errno::ECONNRESET
- Errno::EPROTO
- File
- Object
- WEBrick
- WEBrick::AccessLog
- WEBrick::AccessLog::AccessLogError
- WEBrick::BasicLog
- WEBrick::CGI
- WEBrick::Config
- WEBrick::Config::OpenSSL
- WEBrick::Cookie
- WEBrick::Daemon
- WEBrick::GenericServer
- WEBrick::HTMLUtils
- WEBrick::HTTPAuth
- WEBrick::HTTPAuth::Authenticator
- WEBrick::HTTPAuth::BasicAuth
- WEBrick::HTTPAuth::DigestAuth
- WEBrick::HTTPAuth::Htdigest
- WEBrick::HTTPAuth::Htgroup
- WEBrick::HTTPAuth::Htpasswd
- WEBrick::HTTPAuth::ProxyAuthenticator
- WEBrick::HTTPAuth::ProxyBasicAuth
- WEBrick::HTTPAuth::ProxyDigestAuth
- WEBrick::HTTPAuth::UserDB
- WEBrick::HTTPProxyServer
- WEBrick::HTTPRequest
- WEBrick::HTTPResponse
- WEBrick::HTTPResponse::InvalidHeader
- WEBrick::HTTPServer
- WEBrick::HTTPServerError
- WEBrick::HTTPServlet
- WEBrick::HTTPServlet::AbstractServlet
- WEBrick::HTTPServlet::CGIHandler
- WEBrick::HTTPServlet::DefaultFileHandler
- WEBrick::HTTPServlet::ERBHandler
- WEBrick::HTTPServlet::FileHandler
- WEBrick::HTTPServlet::HTTPServletError
- WEBrick::HTTPServlet::ProcHandler
- WEBrick::HTTPStatus
- WEBrick::HTTPStatus::ClientError
- WEBrick::HTTPStatus::EOFError
- WEBrick::HTTPStatus::Error
- WEBrick::HTTPStatus::Info
- WEBrick::HTTPStatus::Redirect
- WEBrick::HTTPStatus::ServerError
- WEBrick::HTTPStatus::Status
- WEBrick::HTTPStatus::Success
- WEBrick::HTTPUtils
- WEBrick::HTTPUtils::FormData
- WEBrick::HTTPVersion
- WEBrick::Log
- WEBrick::SNIRequest
- WEBrick::ServerError
- WEBrick::SimpleServer
- WEBrick::Utils
- WEBrick::Utils::TimeoutHandler
- WEBrick::Utils::TimeoutHandler::Process

No matching classes.

# WEBrick::HTTPAuth

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.

### Public Instance Methods

basic_auth(req, res, realm) click to toggle source

Simple wrapper for providing basic authentication for a request. When called with a request `req`, response `res`, authentication `realm` and `block` the block will be called with a `username` and `password`. If the block returns true the request is allowed to continue, otherwise an HTTPStatus::Unauthorized error is raised.

                   # File webrick/httpauth.rb, line 79
    def basic_auth(req, res, realm, &block) # :yield: username, password
      _basic_auth(req, res, realm, "Authorization", "WWW-Authenticate",
                  HTTPStatus::Unauthorized, block)
    end

proxy_basic_auth(req, res, realm) click to toggle source

Simple wrapper for providing basic authentication for a proxied request. When called with a request `req`, response `res`, authentication `realm` and `block` the block will be called with a `username` and `password`. If the block returns true the request is allowed to continue, otherwise an HTTPStatus::ProxyAuthenticationRequired error is raised.

                   # File webrick/httpauth.rb, line 91
    def proxy_basic_auth(req, res, realm, &block) # :yield: username, password
      _basic_auth(req, res, realm, "Proxy-Authorization", "Proxy-Authenticate",
                  HTTPStatus::ProxyAuthenticationRequired, block)
    end