couch-client icon indicating copy to clipboard operation
couch-client copied to clipboard

basic auth not working

Open jmarca opened this issue 14 years ago • 2 comments

When trying to create a db with this client, I get {"error":"unauthorized","reason":"You are not a server admin."}

I scanned the code and didn't see anything resembling setting auth headers, even though some of the examples/tests included user:pass@host:port type url strings.

(felixge / node-couchdb works for me, but he's not maintaining anymore...)

My snippet of code that fails follows. user and pass are valid admin, and the couchdb is set to require authentication (not in admin party mode). Also, the database does not yet exist

  var url_obj = {'host':user+':'+pass+'@'+host,
               'port':port,
               'pathname':"/"+dbname };
  var url_string = formatUrl(url_obj);
  console.log ('url string is '+ url_string);

  var cdb  = CouchClient(url_string);
  cdb.request('PUT',"/"+dbname, function(e,r){
      if(e) console.log('e is '+JSON.stringify(e)); // does not trigger0
      console.log('r is '+JSON.stringify(r));
     // prints:
     //  {"error":"unauthorized","reason":"You are not a server admin."}
  });

jmarca avatar Jan 04 '11 19:01 jmarca

Hmm, I thought it used to work, maybe it was a node api change. Either way, you're more than welcome to send a patch to fix this. Basic auth is really simple, but needs to be used over ssl. I haven't yet figured out digest auth.

creationix avatar Jan 04 '11 19:01 creationix

Have a look at my fork. It should work with the patched code. https://github.com/michael/couch-client/commit/011698b10a5d21ab43d86aa277884f92b48e24ed

michael avatar Feb 27 '11 20:02 michael