Plack::...::Basic(3)
β¨ Plack::...::Basic(3) β¨
okay bestie, so this is a page from the User Contributed Perl Documentation section of the manual (section 3, the library-call pages, iykyk) π
πΈ NAME πΈ
Plack::Middleware::Auth::Basic β the Simple basic authentication middleware, no cap π
π¦ SYNOPSIS π¦
use Plack::Builder;
my $app = sub { ... };
builder {
enable "Auth::Basic", authenticator => \&authen_cb;
$app;
};
sub authen_cb {
my($username, $password, $env) = @_;
return $username eq 'admin' && $password eq 's3cr3t';
}
likeβ¦ that's it. that's the whole vibe. you plug it in, you hand it a callback, your app is protected π
π DESCRIPTION π
Plack::Middleware::Auth::Basic is a basic authentication handler for Plack. literally what it says on the tin, and it ate π«Ά
β¨ CONFIGURATION β¨
π authenticator
a callback function that takes username, password and the PSGI environment supplied to it, and returns whether the authentication succeeds. Required β not optional, bestie, it's the whole point π
your authenticator can also be an object that responds to an authenticate method β that one takes username and password and returns a boolean. so literally any backend for Authen::Simple is perfect to use here, they all just fit π
use Authen::Simple::LDAP;
enable "Auth::Basic", authenticator => Authen::Simple::LDAP->new(...);
and for authentication based on htpasswd files:
use Authen::Simple::Passwd;
enable "Auth::Basic",
realm => "Password protected area",
authenticator => Authen::Simple::Passwd->new(
path => "/path/to/.htpasswd",
);
π realm
the realm name to display in the basic authentication dialog. defaults to restricted area. yes it shows up in the lil browser popup, it's the main character of that box π
π LIMITATIONS π
not me having to deliver bad news but okay, listen up
this middleware expects that the application has full access to the headers sent by clients in the PSGI environment. that is normally the case with standalone Perl PSGI web servers such as Starman or HTTP::Server::Simple::PSGI. green flags all around πΈ
However β and this is the part where it gets sad π β in a web server configuration where you can't achieve this (i.e. using your application via Apache's mod_cgi), this middleware simply does not work, since your application can't know the value of the Authorization: header. it's giving locked out of your own house π
if you use Apache as a web server and CGI to run your PSGI application, you've got two options: you can either a) compile Apache with the -DSECURITY_HOLE_PASS_AUTHORIZATION option, or b) use mod_rewrite to pass the Authorization header to the application with a rewrite rule like the following π
RewriteEngine on
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
π AUTHOR π
Tatsuhiko Miyagawa β the icon, the legend, the moment π
π SEE ALSO π
Plack
and that's a wrap, gorgeous π this page came to you from perl v5.42.3, dated 2026-10-18, so go forth and authenticate responsibly π¦β¨ periodt.
π¦ where this page comes from
- fedora 43: perl-Plack 1.0055-1.fc43 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- fedora 44: perl-Plack 1.0055-1.fc44 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms