The following is what I have tried. I have also experimented with
changing the NSURLCredentialPersistence, but nothing has worked.
CouchServer *server = [[CouchServer alloc] initWithURL:serverURL];
[server setCredential:[NSURLCredential credentialWithUser:@"admin"
password:@"secret" persistence:NSURLCredentialPersistenceNone]];
The only way I have been able to authenticate is to use the REST APIs
(e.g. RESTResource, RESTOperation) directly and add the Basic
Authorization header to the RESTOperations before starting them.
RESTOperation *getUserDocument = [userDocumentResource GET];
[getUserDocument setAuthorizationUsername:@"admin"
password@"secret"]; // This is a custom ObjC extension for adding the
Basic Authorization
[[getUserDocument start] wait];
Obviously this means I can't use the Couch APIs (e.g. CouchDocument,
CouchQuery, etc.) which are what I want to use.
Does the NSURLCredential work against CouchDB? Is there a specific way
to configure CouchDB to work with CouchCocoa?
Thanks.
David
server = [[CouchEmbeddedServer alloc] initWithURL: [NSURL URLWithString: USE_REMOTE_SERVER_FOR_DEBUGGING]];
NSURLCredential* credentials = [NSURLCredential
credentialWithUser:@"admin"
password:@"admin"
persistence:NSURLCredentialPersistenceNone];
[server setCredential:credentials];
But I keep getting this error
Couldn't create database: Error Domain=CouchDB Code=401 "unauthorized: You are not a server admin." UserInfo=0xc633780 {NSLocalizedDescription=unauthorized: You are not a server admin., NSUnderlyingError=0xc62cb30 "401 unauthorized", NSLocalizedFailureReason=unauthorized}
[server setCredential:credentials];But I keep getting this errorCouldn't create database: Error Domain=CouchDB Code=401 "unauthorized: You are not a server admin."
; Uncomment next line to trigger basic-auth popup on unauthorized requests. ;WWW-Authenticate = Basic realm="administrator"
I ask because I host mine on IrisCouch.com and I don't know how to set/
uncomment the WWW-Authenticate setting via mydomain.iriscouch.com/
_utils/ …
The workaround is to uncomment the following line in the server's ‘default.ini’ configuration file, or to make the corresponding change in the "[httpd]” section via Futon’s config UI:; Uncomment next line to trigger basic-auth popup on unauthorized requests. ;WWW-Authenticate = Basic realm="administrator"I’m sorry I haven’t documented this. I should at least add to the doc-comment in RESTResource, and maybe also add a wiki page.
> I was not able to set a realm key. When I tried, Futon told me it was read-only. I could not find the key anywhere in the page. Was I supposed to put both assignments on the one line?
Yes. The value of the WWW-Authenticate property is the HTTP header value to return, which is literally
Basic realm="administrator"
(well, without the leading tab)
—Jens