Connecting to Couchbase Cluster - 401 UnAuthorized

I am trying to connect to couchbase cluster to create a new Bucket using ClusterManager.

COuchbase Server: Version: 3.0.2-1603 Enterprise Edition (build-1603)
Below is the code snippet in .NET SDK 2.0.

            var couchbaseInstances = new List() { new Uri("http://localhost:8091/pools") };
            var config = new ClientConfiguration()
            {
                ViewRequestTimeout = 45000,
                Servers = couchbaseInstances,
                PoolConfiguration = new PoolConfiguration { MinSize = 10, MaxSize = 10 }
            };
            var cluster = new Cluster(config);
            var clusterManager = cluster.CreateManager(userName, password);
            var result = clusterManager.CreateBucket(bucketName);

But I get 401 UnAuthorized exception. I used the same userid and password that I use to login to the Couchbase web console. Please help!

Thanks,
Kris

Opppsss… i wrote you something related to 1.3.
I just wrote a quick console and it works.
try it like this:
Couchbase.Configuration.Client.ClientConfiguration config = new Couchbase.Configuration.Client.ClientConfiguration
{
Servers = new List
{
new Uri(“http://127.0.0.1:8091/pools”)
},
};

I tried below. Still no luck. I get 401 UnAuthorized at cluster.CreateManager

            ClientConfiguration config = new ClientConfiguration
            {
                Servers = new List
                {
                    new Uri("http://127.0.0.1:8091/pools")
                },
            };
            using (var cluster = new Cluster(config))
            {
                var clusterManager = cluster.CreateManager("administrator", "password");
                var result = clusterManager.CreateBucket(bucketName);
            }

@kris_smarty

Check the casing on the username: “Administrator” vs “administrator”

-Jeff

Actually the one that I have mentioned in the snippet is not my original credential. I just masked it as administrator/password. But I am sure that I am trying the right case in my username and password.

I am able to login to the web console using the exact same credential. But it gives me 401 when I do the cluster.CreateManager

Some additional information that I see int he exception. Hope it helps!


Unhandled Exception: System.Security.Authentication.AuthenticationException: default ---> System.Net.WebException: The remote server returned an error: (401) Unauthorized.
   at System.Net.WebClient.DownloadDataInternal(Uri address, WebRequest& request)
   at System.Net.WebClient.DownloadString(Uri address)
   at Couchbase.Configuration.Server.Providers.Streaming.HttpServerConfig.DownLoadConfig[T](Uri uri)
   at Couchbase.Configuration.Server.Providers.Streaming.HttpServerConfig.DownloadConfigs(Uri server)
   --- End of inner exception stack trace ---
   at Couchbase.Configuration.Server.Providers.Streaming.HttpServerConfig.DownloadConfigs(Uri server)
   at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source, Func`2 predicate)
   at Couchbase.Configuration.Server.Providers.Streaming.HttpServerConfig.Initialize()
   at Couchbase.Cluster.CreateManager(String username, String password)
   at HiveSubscriptionSetup.Program.Main(String[] args) in d:\TFS\QTX\HIVSYS\QtxUniversity\HiveSubscriptionSetup\HiveSubscriptionSetup\Program.cs:line 35
Press any key to continue . . .

@kris_smarty -

Assuming the user/pass are correct, it should just work. The exception information is consistent with failed authentication at that point, because the manager is trying to get the cluster map and it cannot because it’s not auth’d.

-Jeff

Is the cluster credentials different from the couchbase web console credentials? If so, please let em know how to set the cluster credentials.

@kris_smarty -

I just looked at the source, and the problem is the credentials are not being passed to the HttpServerConfig constructor in Cluster.CreateManager, thus the authentication exception. This is a bug; can you create a Jira ticket for tracking? If not I’ll do it, but if you do it you’ll be sent emails when the status changes.

-Jeff

I created a bug

https://issues.couchbase.com/browse/NCBC-869

Please check if I added the required properties as I did it for the first time for Couchbase. I will use CLI for now.

Thanks!

Here is a screenshoot i just took from my working code (2.0.3.1)

Very weird.

I am using the same version of .NET SDK 2.0.3.1
I am sure my credentials are correct. Same as the web console.
But I get the exception.

Jeff says that there is some bug in the code. I tried same code on another instance of couchbase run on a different box. That failed too.

Hi Jeff,

I see that you got this issue already fixed in the source. When do you think a new version of the nuget will be out for the usage?

Thanks!

@kris_smarty

2.1.0 is scheduled for the first week of May: https://issues.couchbase.com/browse/NCBC#selectedTab=com.atlassian.jira.plugin.system.project%3Aversions-panel

Thanks,

Jeff

Hi Jeff,

Just checking if the Couchbase Client 2.1.0 is published to nuget? Tks

@kris_smarty -

Were still going through QE; once we have a GA build I’ll make a post.

-Jeff