class

Kemal::BasicAuth::Handler

Inherits Kemal::Handler < Kemal::HandlerInterface < HTTP::Handler < Reference < Object

This middleware adds HTTP Basic Auth support to your application. Returns 401 "Unauthorized" with wrong credentials.

basic_auth "username", "password"
# basic_auth({"username1" => "password1", "username2" => "password2"})

HTTP::Server::Context#kemal_authorized_username? is set when the user is authorized.

Constants

AUTH = "Authorization"
AUTH_MESSAGE = "Could not verify your access level for that URL.\nYou have to login with proper credentials"
BASIC = "Basic"
BASIC_PREFIX = "Basic "
DEFAULT_REALM = "Login Required"
HEADER_LOGIN_REQUIRED = "Basic realm=\"#{DEFAULT_REALM}\""
RATE_LIMIT_MESSAGE = "Too many failed authentication attempts. Please try again later."
RATE_LIMIT_RETRY_AFTER = "60"

Constructors

new(verifier : Verifier, realm : String = DEFAULT_REALM, message : String = AUTH_MESSAGE, rate_limiter : RateLimiter | Nil = nil)
Source
new(username : String, password : String, realm : String = DEFAULT_REALM, message : String = AUTH_MESSAGE, rate_limiter : RateLimiter | Nil = nil)

backward compatibility

Source
new(hash : Hash(String, String), realm : String = DEFAULT_REALM, message : String = AUTH_MESSAGE, rate_limiter : RateLimiter | Nil = nil)
Source

Instance methods

authorize?(value) : String | Nil
Source
call(context)
Source
message
Source
rate_limiter
Source
realm
Source

Macros

exclude(paths, method = "GET")
Source
only(paths, method = "GET")
Source