How do I use a php authentication script as proxy to CouchDB and still maintain full REST API functionality?-Collection of common programming errors


  • Inator

    I’ve recently successfully installed CouchDB version 1.2.1 and as a test I can access it using the following Apache rewrite in CentOS 6:

    RewriteRule couchdb/(.*)$ http://127.0.0.1:5984/$1 [QSA,P]
    

    I have a PHP authentication class that I use across a home grown API to support my mobile apps. My API accepts and authenticates each request using an HMAC signature that is included in the URL like so:

    https://api.domain.com/endpoint/?timestamp=[timestamp]&signature=[signature]&id=[id]...etc
    

    Each endpoint has a corresponding script that ensures that checks for a proper signature before processing.

    Ideally, I’d like to effectively replace the above reverse proxy rewrite rule with some sort of PHP script that will act as a gatekeeper/gateway to the CouchDB instance, leveraging my authentication class, while still preserving all native CouchDB REST API functionality, including but not limited to replication and cookie authentication for users (the above is just for API authentication). Can this be done? I’ve tried using this solution as modified below, but while it does in fact kick back valid JSON responses, replication fails, and I suspect other aspects such as user authentication will as well:

    
    
    
    
    

    I’ve been at this for days and I can’t seem to make it work so I’m tossing it out for help either getting the php proxy script right, or help identifying an alternative approach.


  • djc

    I would guess that replication (like the _changes feed, for example) uses long-lived requests with chunked transfer-encoding, and your PHP proxy doesn’t support that well.