The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

HTTP::Server::Simple::Authen - Authentication plugin for HTTP::Server::Simple

SYNOPSIS

  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');
  }

  MyServer->new->run();

DESCRIPTION

HTTP::Server::Simple::Authen is an HTTP::Server::Simple plugin to allow HTTP authentication. Authentication scheme is pluggable and you can use whatever Authentication protocol that Authen::Simple supports.

METHODS

Your subclass has to override following methods to implement HTTP authentication.

authen_handler

Should return a valid Authen::Simple instance to authenticate HTTP request (Required).

authen_realm

Returns a string for Authentication realm to be shown in the browser's dialog box. Defaults to 'Authorized area'.

needs_authen

Returns true if the request needs authentication. Takes $cgi as a parameter. Default to return 1 (which means all the requests should be authenticated).

For example, you can use the following code to authenticate URL under /foo/.

  sub needs_authen {
      my($self, $cgi) = @_;
      return $cgi->path_info =~ m!/foo/!;
  }
authorize_user

Returns true if you allow authenticated user to access the content. Takes username as a parameter. By default it always returns true, which means the same thing with Apache's Require valid-user.

The following code means it only authorizes usernames with 8 chars long.

  sub authorize_user {
      my($self, $username) = @_;
      return length($username) == 8;
  }

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.

SEE ALSO

HTTP::Server::Simple, Authen::Simple