HTTP::...Authen(3pm)

πŸ“¦
version 0.04 Β· 4 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

✨ 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 valid Authen::Simple instance 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::Simple
  • Authen::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