Apache::AuthCookie allows you to intercept a users first unauthenticated access to a protected document. The user will be presented with a custom form where they can enter thier authentication credentials. The credentials are posted to the server where AuthCookie verifies them and generates a session key.

The session key is returned to the user's browser as a cookie. As a cookie, the browser will pass the session key on every subsequent accesses. AuthCookie will verify the session key and re-authenticate the user.

All you have to do is write a custom package that inheriets from AuthCookie. Your package implements two functions:

The client doesn't *have* to pass the user credentials on every subsequent access. You have to do a little more work to get this feature, by having authen_cred() generate a session key.

When you determine that the client should stop using the credentials/session key, the server can tell the client to delete the cookie.

This is the flow of the authentication handler, less the details of the redirects. Two REDIRECT's are used to keep the client from displaying the user's credentials in the Location field. They don't really change AuthCookie's model, but they do add another round-trip request to the client.

Try to access /unprotected/protected/get_me.html. You should instead get a form requesting a login and password. The sample will validate two users. The first is login => programmer and password => Hero and the second is login => some-user with no/any password. You might want to set your browser to show you cookies before accepting them. Then you can see what AuthCookie is generating.

As distributed, the .htaccess file in eg/unprotected/protected will allow either of these user to access the document. However if you change the line require valid-user to require dwarf in .htaccess only the user "programmer" will have access. Look at the authorization function dwarf() in eg/Sample/AuthCookieHandler.pm to see how this works.

See if there's a way to allow the initial request to be a POST. I know Apache::AuthCookie could save the original POST'ed material but I don't know how to re-insert this content into the request stream after the user authenticates. If you knows of a way, please drop me a note.

Create a session key store that uses shared memory. If anyone wants to get together and help with this that would be cool. Storing and retrieving them should be easy, but the harder part is cleaning out "old" keys and dealing with server restarts without losing all the keys.