Authentication middleware for CouchDB