CouchbaseError Authentication failed

I get ‘Authentication failed error’ when I try to connect to a couchbase cluster with Node.js sdk.

There’s not a password for the bucket, instead is set username & password for the whole Cluster, that are the same I use to login in the Administration panel from browser.

Where do I have to put username and password ? I tried everything, I put them in the connection string in the Cluster constructor, I tried to add username and password as second parameter of the Cluster object, but it didn’t work.

In all examples online they always use only this line of code

var cluster = new couchbase.Cluster('couchbase://localhost/');
var bucket = cluster.openBucket('bucket_name');

But in my case the cluster isn’t located in localhost and I need to provide username and password in addiction to the host.

this is my code:

var cnstr = 'http://'+conf.host;
 var myCluster = new couchbase.Cluster(cnstr,{username:'root',password:conf.password});

var myBucket = myCluster.openBucket('bucketname',function(err,res){
    if(err){
        console.log(err);
    }
});

this is the error

{ CouchbaseError: Authentication failed. You may have provided an invalid username/password combination
   message: 'Authentication failed. You may have provided an invalid username/password combination',
  code: 2 }

can anyone help me ?

Alessandro

1 Like

why did you replace couchbase:// with http://?

that was an attempt to solve the problem…I get the same error even with couchbase://

Not tried, but second param for openBucket should be the passwort … have you tried something like this:

var conf = { host: 'yourremotecbhostip' }; var cluster = new couchbase.Cluster('couchbase://' + conf.host + '/'); var myBucket = myCluster.openBucket('bucketname','', function(err,res){ if(err){ console.log(err); } });

?

I tried but it doesn’t’ work. Still get the same error.

it’ very weird because from the documentation here

they say

To configure the client, instantiate a new Cluster object:

 var couchbase = require('couchbase');
 var myCluster = new couchbase.Cluster('couchbase://10.4.4.1');

In addition to the connection string passed to the Cluster object, you can include a user name and password.

The user name and password are required to perform management operations against your cluster. If you do not use the cluster management aspects of the SDK, the user name and password parameters are optional. Keep in mind that these credentials are the same ones you use to log in to the Couchbase administrator console, not those specified for the bucket itself.

The problem is that there’s not an example that explain how and where put user and pass.

Thanks for your solution. It worked for me, when I was getting strange error messages like:

(Authentication failed for user ‘travel-sample’)) (travel-sample)

when my user is not ‘travel-sample’ but that is the bucket.

BROKEN

var config = new ClientConfiguration
{
	Servers = new List<Uri> { new Uri("http://127.0.0.1:8091/") },
	BucketConfigs = new Dictionary<string, BucketConfiguration> {
	  {"travel-sample", new BucketConfiguration {
		  BucketName = "travel-sample",
		  Username = "TestUser",
		  Password = "Test@111"
	  }}
	}
};
ClusterHelper.Initialize(config);

var context = new BucketContext(ClusterHelper.GetBucket("travel-sample"));

FIXED

Cluster cluster = new Cluster(
  new Couchbase.Configuration.Client.ClientConfiguration()
  {
	  Servers = new List<Uri> { new Uri("http://127.0.0.1:8091/") }
  }
);
var auth = new Couchbase.Authentication.PasswordAuthenticator("TestUser", "Test@111");
cluster.Authenticate(auth);

ClusterHelper.Initialize(cluster.Configuration);

var context = new BucketContext(ClusterHelper.GetBucket("travel-sample"));