Skip to content

Instantly share code, notes, and snippets.

@rwp0
Last active April 29, 2024 19:45
Show Gist options
  • Save rwp0/afd07a2377833bc754260398a387531c to your computer and use it in GitHub Desktop.
Save rwp0/afd07a2377833bc754260398a387531c to your computer and use it in GitHub Desktop.
HTTP Auth-Basic login prompt with Plack Perl web server
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 ]
];
}
};
@rwp0
Copy link
Author

rwp0 commented Apr 29, 2024

This illustrates the point referenced in Plack's Auth::Basic middleware:

Using Authen::Simple::Passwd (file) to authenticate against

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment