Couchbase lite and couchbase sync gate way authentication failed

I am using following code to connect my couchabse-lite to sync gate way:
URL url = new URL(“http://localhost:4984/sync_gateway/”);
Replication push = db.createPushReplication(url);
Replication pull = db.createPullReplication(url);
pull.setContinuous(true);
push.setContinuous(true);
com.couchbase.lite.auth.Authenticator auth = AuthenticatorFactory.createBasicAuthenticator(“guest”, “!”);
push.setAuthenticator(auth);
push.setAuthenticator(auth);
pull.setAuthenticator(auth);
push.start();
pull.start();

getting following exception:
java.io.FileNotFoundException: settings.txt (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.(FileInputStream.java:146)
at java.io.FileInputStream.(FileInputStream.java:101)
at omnibazaar.GreetingServer.run(GreetingServer.java:161)
Jun 02, 2015 10:29:24 PM com.couchbase.lite.util.SystemLogger e
SEVERE: RemoteRequest: Got error status: 401 for http://localhost:4984/sync_gateway/_session. Reason: Unauthorized
Jun 02, 2015 10:29:24 PM com.couchbase.lite.util.SystemLogger e
SEVERE: RemoteRequest: Got error status: 401 for http://localhost:4984/sync_gateway/_session. Reason: Unauthorized
Jun 02, 2015 10:29:24 PM com.couchbase.lite.util.SystemLogger e
SEVERE: Sync: com.couchbase.lite.replicator.ReplicationInternal$4@780c94eb: Session check failed
org.apache.http.client.HttpResponseException: Unauthorized
at com.couchbase.lite.support.RemoteRequest.executeRequest(RemoteRequest.java:222)
at com.couchbase.lite.support.RemoteRequest.run(RemoteRequest.java:104)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:178)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:292)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)

Hi @zeeshan_niazi,

It looks like Sync Gateway is returning 401 Unauthorized responses.

If you use basic authentication with name: guest and password: !, that user must exist on Sync Gateway.
You can create users like so:

curl -vX POST -H 'Content-Type: application/json' \
       -d '{"name": "guest", "password": "!"}'
       http://localhost:4985/sync_gateway/_user/

A side note to clarify the guest account mode: note that “guest account” is a terminology used to describe anonymous requests (see here) and if the guest account is enabled in the Sync Gateway config then you shouldn’t need the basic authenticator.

Hope this helps
James

where I can run this command to authenticate user:

curl -vX POST -H ‘Content-Type: application/json’
-d '{“name”: “guest”, “password”: “!”}'
http://localhost:4985/sync_gateway/_user/

This request is to create a user.

You can then user this username/password in the AuthenticatorFactory.createBasicAuthenticator class to authenticate as this user.
I think you are getting 401 Unauthorized errors in the logs you pasted above because this user doesn’t exist in Sync Gateway.