1HTTP::Server::Simple::AUustehrenC(o3n)tributed Perl DocuHmTeTnPt:a:tSieornver::Simple::Authen(3)
2
3
4
6 HTTP::Server::Simple::Authen - Authentication plugin for
7 HTTP::Server::Simple
8
10 package MyServer;
11 use base qw( HTTP::Server::Simple::Authen HTTP::Server::Simple::CGI);
12
13 use Authen::Simple::Passwd;
14 sub authen_handler {
15 Authen::Simple::Passwd->new(passwd => '/etc/passwd');
16 }
17
18 sub handle_request {
19 my($self, $cgi) = @_;
20 my $user = $self->authenticate or return;
21 ...
22 }
23
24 MyServer->new->run();
25
27 HTTP::Server::Simple::Authen is an HTTP::Server::Simple plugin to allow
28 HTTP authentication. Authentication scheme is pluggable and you can use
29 whatever Authentication protocol that Authen::Simple supports.
30
31 You can use "authenticate" method whatever you want to authenticate the
32 request. The method returns $username taken from the request if the
33 authentication is successful, and "undef" otherwise. The code in
34 "SYNOPSIS" requires authentication for all the requests and behaves
35 just the same as Apache's "Require valid-user".
36
37 The following code will explain more about conditioning.
38
39 sub handle_request {
40 my($self, $cgi) = @_;
41 if ($cgi->path_info =~ m!/foo/!) {
42 my $user = $self->authenticate;
43 return unless defined($user) && length($user) == 8;
44 }
45 ...
46 }
47
48 This means all the requests to URL "/foo/" require to be authenticated,
49 and usernames with 8 chars long are authorized.
50
52 Your subclass has to override following methods to implement HTTP
53 authentication.
54
55 authen_handler
56 Should return a valid Authen::Simple instance to authenticate HTTP
57 request (Required).
58
59 authen_realm
60 Returns a string for Authentication realm to be shown in the
61 browser's dialog box. Defaults to 'Authorized area'.
62
64 Tatsuhiko Miyagawa <miyagawa@bulknews.net>
65
66 This library is free software; you can redistribute it and/or modify it
67 under the same terms as Perl itself.
68
70 HTTP::Server::Simple, Authen::Simple
71
72
73
74perl v5.32.0 2020-07-28 HTTP::Server::Simple::Authen(3)