class Kemal::BasicAuth::Handler

Overview

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.

Defined in:

kemal-basic-auth/handler.cr

Constant Summary

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

Macro Summary

Instance Method Summary

Constructor Detail

def self.new(verifier : Verifier, realm : String = DEFAULT_REALM, message : String = AUTH_MESSAGE, rate_limiter : RateLimiter | Nil = nil) #

[View source]
def self.new(username : String, password : String, realm : String = DEFAULT_REALM, message : String = AUTH_MESSAGE, rate_limiter : RateLimiter | Nil = nil) #

backward compatibility


[View source]
def self.new(hash : Hash(String, String), realm : String = DEFAULT_REALM, message : String = AUTH_MESSAGE, rate_limiter : RateLimiter | Nil = nil) #

[View source]

Macro Detail

macro exclude(paths, method = "GET") #

[View source]
macro only(paths, method = "GET") #

[View source]

Instance Method Detail

def authorize?(value) : String | Nil #

[View source]
def call(context) #

[View source]
def message : String #

[View source]
def rate_limiter : RateLimiter | Nil #

[View source]
def realm : String #

[View source]