HTTP::...Authen(3pm)
β¨ NAME β¨
okay so bestie, gather round π this one is HTTP::Server::Simple::Authen β it's the authentication plugin for HTTP::Server::Simple. that's it, that's the whole name, no notes π
π SYNOPSIS π
here's the vibe, literally copy-paste energy:
package MyServer;
use base qw( HTTP::Server::Simple::Authen HTTP::Server::Simple::CGI);
use Authen::Simple::Passwd;
sub authen_handler {
Authen::Simple::Passwd->new(passwd => '/etc/passwd');
}
sub handle_request {
my($self, $cgi) = @_;
my $user = $self->authenticate or return;
...
}
MyServer->new->run();
like. look at that. chef's kiss π«Ά
πΈ DESCRIPTION πΈ
HTTP::Server::Simple::Authen is an HTTP::Server::Simple plugin that lets you do HTTP authentication. and the way it's built?? the authentication scheme is pluggable β you can use literally whatever authentication protocol Authen::Simple supports. no cap. π
you can call the authenticate method whenever you want to authenticate a request. it returns the $username pulled from the request if the authentication worked, and undef if it didn't. periodt.
the code up in the SYNOPSIS makes authentication required for all the requests, and it behaves exactly the same as Apache's Require valid-user. iconic behaviour honestly π
the following code explains more about conditioning:
sub handle_request {
my($self, $cgi) = @_;
if ($cgi->path_info =~ m!/foo/!) {
my $user = $self->authenticate;
return unless defined($user) && length($user) == 8;
}
...
}
so what this means is: every request to the URL /foo/ has to be authenticated, and usernames that are 8 chars long are the authorized ones. very specific, very demure β¨
π METHODS π
your subclass has got to override these following methods to actually implement HTTP authentication. no skipping, bestie π€
authen_handlerβ should return a validAuthen::Simpleinstance to authenticate the HTTP request. this one is Required. (yes, capital-R Required, the manpage said it, I'm just the messenger π)authen_realmβ returns a string for the Authentication realm that shows up in the browser's dialog box. defaults to'Authorized area'. cute default tbh π
π¦ AUTHOR π¦
Tatsuhiko Miyagawa <miyagawa@bulknews.net>
this library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. (so like, go off, but responsibly π)
π SEE ALSO π
HTTP::Server::SimpleAuthen::Simple
okay that's the whole page, you're welcome π«Ά this was perl v5.36.0, dated 2022-12-12, and it's been real. mwah πβ¨
π¦ where this page comes from
- debian bookworm: libhttp-server-simple-authen-perl 0.04-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libhttp-server-simple-authen-perl 0.04-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libhttp-server-simple-authen-perl 0.04-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libhttp-server-simple-authen-perl 0.04-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libhttp-server-simple-authen-perl 0.04-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms