Last active
April 29, 2024 19:45
-
-
Save rwp0/afd07a2377833bc754260398a387531c to your computer and use it in GitHub Desktop.
HTTP Auth-Basic login prompt with Plack Perl web server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use v5.38; | |
use Plack::Builder; | |
use Authen::Simple::Passwd; | |
use Log::Log4perl; # For additional logging from Authen::Simple::Passwd | |
Log::Log4perl -> easy_init(); | |
builder { | |
enable 'Auth::Basic' , | |
realm => 'My Plack Perl Web Server' , | |
authenticator => Authen::Simple::Passwd -> new( | |
path => "$ENV{HOME}/.htpasswd" , # File: <user>:<password> | |
log => Log::Log4perl -> get_logger( 'Authen::Simple::Passwd' ) , | |
); | |
sub { | |
return [ 200 , | |
[ 'Content-Type' => 'text/plain' ] , | |
[ 'Some text' . rand ] | |
]; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This illustrates the point referenced in Plack's Auth::Basic middleware:
Using Authen::Simple::Passwd (file) to authenticate against