This http://code.google.com/p/mod-auth-external/ is useful when you need to provide http basic auth ,but authorise from an external program and not htpasswd file.

The installation and confiugration outlined at http://code.google.com/p/mod-auth-external/wiki/Installation worked for me.I was on a Ubuntu 11.04 , so httpd was replaced by apache2 and apxs was apxs2.There is an example perl script in the source code :

http://code.google.com/p/mod-auth-external/source/browse/trunk/mod_authnz_external/test/test.pipe

Here is my ruby version of it :

This is almost what I used later on: