couchdbkit icon indicating copy to clipboard operation
couchdbkit copied to clipboard

BasicAuth CouchDB Example

Open awstanley opened this issue 13 years ago • 1 comments

I looked around before posting this, but if I missed it in the channel, group, or another ticket, I apologise.

I noticed there was no example for authentication (cf. BasicAuth) against CouchDB. I was thinking it might be nice to put an official example of using BasicAuth up in the docs. I assume what I worked out is right, but I'm filing this here because there may already be a cleaner way, or this may be less than efficient for some reason. (And this probably belongs in docs, not on the wiki, but I'm happy to put it there if it's a better idea)

import couchdbkit
from restkit import BasicAuth

uri = "http://127.0.0.1:5984/"
username = "CouchDBUsername"
password = "CouchDBPassword"

CouchDBAuth = couchdbkit.resource.CouchdbResource(filters=[BasicAuth(username, password)])
CouchDBServer = couchdbkit.Server(uri, resource_instance=CouchDBAuth)

As the function is already in restkit, I assume there's no reason to configure helpers/wrappers for CouchDB to do this, and I also assume that OAuth is similar (though I wouldn't know and can't test, I only use BasicAuth for CouchDB at the moment).

awstanley avatar May 28 '12 22:05 awstanley

Thanks for thar :) It could be on the wiki in a recipe part Imo waiting the big doc rewrite. Also you can do :

uri = "http://username:[email protected]:5984/"
CouchDBServer = couchdbkit.Server(uri)

It will works as well :)

benoitc avatar Jun 06 '12 06:06 benoitc