.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "AuthenHook 3pm" .TH AuthenHook 3pm 2024-03-07 "perl v5.38.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME Apache::AuthenHook \- Perl API for Apache 2.1 authentication .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 1 \& PerlLoadModule Apache::AuthenHook \& \& PerlModule My::OtherProvider \& \& \& Require valid\-user \& AuthType Digest \& AuthName realm1 \& \& AuthDigestProvider My::DigestProvider file My::OtherProvider::digest \& \& AuthUserFile realm1 \& \& \& \& Require valid\-user \& AuthType Basic \& AuthName foorealm \& \& AuthBasicProvider My::OtherProvider::basic file My::BasicProvider \& \& AuthUserFile realm1 \& .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" Apache::AuthenHook offers access to the 2.1 Apache authentication API in Perl. This is different than the authentication API from Apache 1.3 or even Apache 2.0, but in its differences lies strength. .PP For a full description of how authentication works in 2.1, see .PP http://www.serverwatch.com/tutorials/article.php/2202671 .PP Basically, the difference between 2.0 and 2.1 is that authentication is now delegated to providers, and each provider has a specific purpose. For instance, mod_authn_file covers gleaning the password from an .htpasswd or .htdigest file, while mod_auth_basic covers the Basic dialogue between the client and server, regardless of the source of the password. The best part of all this (to me) is that Digest authentication is also delegated out \- mod_auth_digest now handles all the intricacies of Digest authentication (including the elusive MSIE support) which means you don't need to worry about them (and neither do I). All that Digest authentication requires is *some* authentication provider to provide user credentials \- this can be via mod_authn_file or another mechanism of your choosing. .PP Apache::AuthenHook registers and coordinates the use of Perl handlers as authentication providers. .PP How does this affect you? Read on... .SH EXAMPLE .IX Header "EXAMPLE" Say you want to enable Digest authentication in your Apache 2.1 server... .PP .Vb 1 \& PerlLoadModule Apache::AuthenHook \& \& \& Require valid\-user \& AuthType Digest \& AuthName realm1 \& \& AuthDigestProvider My::DigestProvider file \& \& AuthUserFile realm1 \& .Ve .PP This configuration means that My::DigestProvider will be responsible for providing user credentials for requests to /digest. if My::DigestProvider finds a suitable user, mod_auth_digest will verify those credentials and take care of setting all the proper headers, set the proper HTTP response status, and so on. If My::DigestProvider cannot find a matching user it can decide what to do next \- either pass the user to the next provider (in this case the default file provider, which will use the flat file "realm1") or decide that no user means no access. .PP Here is a simple My::DigestProvider .PP .Vb 1 \& use Apache2::Const \-compile => qw(OK DECLINED HTTP_UNAUTHORIZED); \& \& sub handler { \& \& my ($r, $user, $realm, $hash) = @_; \& \& # user1 at realm1 is found \- pass to mod_auth_digest \& if ($user eq \*(Aquser1\*(Aq && $realm eq \*(Aqrealm1\*(Aq) { \& $$hash = \*(Aqeee52b97527306e9e8c4613b7fa800eb\*(Aq; \& return Apache2::Const::OK; \& } \& \& # user2 is denied outright \& if ($user eq \*(Aquser2\*(Aq && $realm eq \*(Aqrealm1\*(Aq) { \& return Apache2::Const::HTTP_UNAUTHORIZED; \& } \& \& # all others are passed along to the next provider \& return Apache2::Const::DECLINED; \& } .Ve .PP isn't that easy? .PP the only thing that is a bit tricky here is $$hash. the fourth argument passed to your handler, \f(CW$hash\fR, is a reference to to a simple scalar that needs to be populated with the MD5 hash of the user:realm:password combination you determine for the incoming user. this may seem a bit strange, but it is actually exactly how things work over in Apache C land, so I guess that makes it ok. .PP as you can see, returning OK means "user found" and requires that $$hash be populated \- mod_auth_digest will take care of determining whether the hash matches the incoming Digest criteria. returning HTTP_UNAUTHORIZED (which is the same as the former and still available AUTH_REQUIRED constant) means "no access." returning DECLINED means "some other provider can try." .PP The steps are remarkably similar for Basic authentication, first .PP .Vb 4 \& \& Require valid\-user \& AuthType Basic \& AuthName foorealm \& \& AuthBasicProvider My::BasicProvider file \& \& AuthUserFile realm1 \& .Ve .PP then .PP .Vb 1 \& use Apache2::Const \-compile => qw(OK DECLINED HTTP_UNAUTHORIZED); \& \& sub handler { \& \& my ($r, $user, $password) = @_; \& \& # user1/basic1 is ok \& if ($user eq \*(Aquser1\*(Aq && $password eq \*(Aqbasic1\*(Aq) { \& return Apache2::Const::OK; \& } \& \& # user2 is denied outright \& if ($user eq \*(Aquser2\*(Aq) { \& return Apache2::Const::HTTP_UNAUTHORIZED; \& } \& \& # all others are passed along to the next provider \& return Apache2::Const::DECLINED; \& } .Ve .PP In the case of Basic authentication, the return codes mean essentially the same thing. The one exception is that OK means that you have checked the user against the password and have found that they match (as opposed to with Digest, where the actual verification is not done by you). .PP These explanations should be enough to get you going \- see the files in the test suite for more examples. .SH NOTES .IX Header "NOTES" This has been tested under the prefork MPM only, using mostly Perl 5.9.0 (as well as some 5.8.0). It will not work under threaded MPMs \- soon, just not yet. .SH FEATURES/BUGS .IX Header "FEATURES/BUGS" This is very much so alphaware, so beware \- bugs may lurk in unexpected places. there is one bug that is outside of my control, though, and concerns MSIE and Digest authentication for URIs that include query strings. see .PP http://httpd.apache.org/docs\-2.0/mod/mod_auth_digest.html .PP one workaround for this issue is is to use POST instead of GET for your forms. .PP A limitation of this interface is that you can't use Perl providers that are not at least two levels deep \- the criterion for registering a Perl provider is a simple check for a double-colon. for example, My::Provider will work while Provider won't (although Provider::handler will). anyway, single level handlers are rare, so fixing it would be a lot of trouble for little benefit. .SH AUTHOR .IX Header "AUTHOR" Geoffrey Young .SH COPYRIGHT .IX Header "COPYRIGHT" Copyright (c) 2003, Geoffrey Young .PP All rights reserved. .PP This module is free software. It may be used, redistributed and/or modified under the same terms as Perl itself.