NAME
PAGI::Middleware::Auth::Basic - HTTP Basic Authentication middleware
SYNOPSIS
use PAGI::Middleware::Builder;
my $app = builder {
enable 'Auth::Basic',
realm => 'Restricted Area',
authenticator => sub {
my ($username, $password) = @_;
return $username eq 'admin' && $password eq 'secret';
};
$my_app;
};
# In your app:
async sub app {
my ($scope, $receive, $send) = @_;
my $auth = $scope->{'pagi.auth'};
my $username = $auth->{username};
}
DESCRIPTION
PAGI::Middleware::Auth::Basic implements HTTP Basic Authentication (RFC 7617). It validates credentials and returns 401 Unauthorized for failed authentication.
CONFIGURATION
authenticator (required)
Coderef that receives ($username, $password) and returns true for valid credentials.
realm (default: 'Restricted')
The authentication realm shown in the WWW-Authenticate header.
paths (optional)
Arrayref of path patterns to protect. If not specified, all paths are protected.
SCOPE EXTENSIONS
This middleware adds the following to $scope when authentication succeeds:
pagi.auth
Hashref with authentication info:
{ type => 'basic', username => 'the-username', }
SECURITY CONSIDERATIONS
HTTP Basic Authentication transmits credentials in base64 encoding (not encrypted). Always use HTTPS when using Basic Authentication in production.
SEE ALSO
PAGI::Middleware - Base class for middleware
PAGI::Middleware::Auth::Bearer - Bearer token authentication