Apache::AuthDigest::API - mod_perl API for Digest authentication


  PerlModule Apache::AuthDigest::API
  PerlModule My::DigestAuthenticator

  <Location /protected>
    PerlAuthenHandler My::DigestAuthenticator
    Require valid-user
    AuthType Digest
    AuthName "cookbook"


Apache::AuthDigest::API is a simple API for interacting with Digest authentication. For more information on Digest authentication, see RFC 2617:

The API itself is very similar to the API mod_perl offers natively for Basic authentication:

  mod_perl's Basic support       AuthDigest::API equivalent

    my $r = shift;                 $r = Apache::AuthDigest::API->new(shift)

    $r->get_basic_auth_pw()        $r->get_digest_auth_response()       

    $r->note_basic_auth_failure    $r->note_digest_auth_failure()

    [none]                         $r->compare_digest_response()

see Recipe 13.8 in the mod_perl Developer's Cookbook for a far more detailed explanantion than will be covered here.


creates a new Apache::AuthDigest::API object. Apache::AuthDigest::API is a subclass of the Apache class so, with the exception of the addition of new methods, $r can be used the same as if it were a normal Apache object

  my $r = Apache::AuthDigest::API->new(Apache->request);

this parses out the authentication header sent by the client. it returns a status and a reference to a hash representing the client Digest request (if any).

  my ($status, $response) = $r->get_digest_auth_response;
  return $status unless $status == OK;

sets the proper authentication headers which prompt a client to send a proper Digest request in order to access the requested resource.


this method represents a shortcut for comparing a client Digest request with whatever credentials are stored on the server. the first argument is the hash reference returned by get_digest_auth_response(). the second argument is a MD5 digest of the user credentials. the credentials should be in the form


before they are hashed. the following Perl one-liner will generate a suitable digest:

  $ perl -MDigest::MD5 -e'print Digest::MD5::md5_hex("user:realm:password"),"\n"'


for a complete example, see the My/ file in the test suite for this package, as well as In general, the steps are the same as for Basic authentication, examples of which abound on CPAN, the Eagle book, and the Cookbook:

  use Apache::AuthDigest::API;

  sub handler {

    my $r = Apache::AuthDigest::API->new(shift);

    my ($status, $response) = $r->get_digest_auth_response;

    return $status unless $status == OK;

    my $digest = my_get_user_credentials_routine($r->user, $r->auth_name);

    return OK if $r->compare_digest_response($response, $digest);

    return AUTH_REQUIRED;


this module essentially mimics the Digest implementation provided by mod_digest.c that ships with Apache. there is another implementation, classified as "experimental" that also ships with Apache, mod_auth_digest.c, which is more complete wrt RFC 2617. of particular interest is that the mod_digest implementation does not work with MSIE (so neither does this implemenation). at some point, Apache::AuthDigest::API::Full will implement a completely compliant API - this will have to do for now.


none that I know of yet, but consider this alphaware.


perl(1), mod_perl(1), Apache(3), Apache::AuthDigest(3)


Geoffrey Young <>

Paul Lindner <>

Randy Kobes <>


Copyright (c) 2002, Geoffrey Young, Paul Lindner, Randy Kobes.

All rights reserved.

This module is free software. It may be used, redistributed and/or modified under the same terms as Perl itself.


This code is derived from the Cookbook::DigestAPI module, available as part of "The mod_perl Developer's Cookbook".

For more information, visit