Hi.

I authenticate with couchbase. I thought things were good but when a delta 
is pushed I get invalid user.
I am using custom authentication. I get a cookie value from the sync 
gateway but I don't see anything in the sync gateway logs about user 
logging in as I did when I was using persona. 
Here is the logs from my android client

05-22 15:00:18.060: D/Syncer(18540): Putting cookie into replicator of type 
pull cookie = SyncGatewaySession=7dad25e46b2fed3f5ac9cfc0f09e6952232ad7e9; 
Expires=2014-05-23T22:00:19.008067287Z; 
Token=FFE4B8305E6EEEEEEEEE636184E5CC6; Username=brianh 

05-22 15:00:18.060: D/Syncer(18540): Putting cookie into replicator of type 
push cookie = SyncGatewaySession=7dad25e46b2fed3f5ac9cfc0f09e6952232ad7e9; 
Expires=2014-05-23T22:00:19.008067287Z; 
Token= FFE4B8305E6EEEEEEEEE636184E5CC6; Username=brianh 
… 
… 
… 
05-22 15:01:18.665: E/Sync(18540): Exception getting status from 
{error=forbidden, id=brianh, reason=wrong user, status=403} 
05-22 15:01:18.665: E/Sync(18540): java.lang.ClassCastException: 
java.lang.Integer cannot be cast to java.lang.String 
05-22 15:01:18.665: E/Sync(18540): at 
com.couchbase.lite.replicator.Pusher.statusFromBulkDocsResponseItem(Pusher.java:445)
 

05-22 15:01:18.665: E/Sync(18540): at 
com.couchbase.lite.replicator.Pusher.access$400(Pusher.java:44) 
05-22 15:01:18.665: E/Sync(18540): at 
com.couchbase.lite.replicator.Pusher$3.onCompletion(Pusher.java:390) 
05-22 15:01:18.665: E/Sync(18540): at 
com.couchbase.lite.support.RemoteRequest$2.run(RemoteRequest.java:277) 
05-22 15:01:18.665: E/Sync(18540): at 
java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422) 
05-22 15:01:18.665: E/Sync(18540): at 
java.util.concurrent.FutureTask.run(FutureTask.java:237) 
05-22 15:01:18.665: E/Sync(18540): at 
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:152)
 

05-22 15:01:18.665: E/Sync(18540): at 
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:265)
 

05-22 15:01:18.665: E/Sync(18540): at 
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 

05-22 15:01:18.665: E/Sync(18540): at 
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 

05-22 15:01:18.665: E/Sync(18540): at java.lang.Thread.run(Thread.java:841)


Code setting the cookie on the replications. The replicators are started 
shortly afterward.

   private void updateReplicators(Authenticator authenticator) {
               Database database = getDatabase(databaseName);
               String cookie = CookieManager.getInstance().getCookie(syncUrl
.toExternalForm());
               boolean shouldUseCookies = !(authenticator instanceof 
BasicAuthenticator);
               if (shouldUseCookies && cookie == null) {
                       Log.d(TAG,  "Using cookie based authentication 
however no cookies have been set for key "+ syncUrl.toExternalForm());
               }
               List<Replication> replications = getAllReplications(database
);
               if (replications != null) {
                       for (Replication replication : replications) {
                               if (shouldUseCookies) {
                                       String type = replication.isPull() ? 
"pull" : "push";
                                       Log.d(TAG, "Putting cookie into 
replicator of type "+ type +" cookie = "+ cookie);
                                       replication.getHeaders().put("Cookie"
, cookie);
                               } else {
                                       replication.deleteCookie(syncUrl.
toExternalForm());
                                       replication.getHeaders().put("Cookie"
, null);
                                       CookieManager.getInstance().setCookie
(syncUrl.toExternalForm(), null);
                               }
                               replication.setAuthenticator(authenticator);
                               replication.stop();
                       }
               }
       }


Here is my config.json - updated to simply check for userid of "brianh"

 {
    "interface": ":4984",
        "adminInterface": ":4985",
        "log": ["CRUD", "CRUD+", "HTTP", "HTTP+", "Access", "Cache", 
"Shadow", "Shadow+", "Changes", "Changes+"],
        "databases": {
        "bsg_sync": {
                    "server": "http://localhost:8091";,
                    "bucket": "bsg_sync",
          "users": {
                          "GUEST": {"disabled": false, "admin_channels":["*"
], "all_channels":["*"]}
          },
          "sync": `function(doc, oldDoc) {
                                channel(doc.channels);
                if (doc.type == "profile") {
                   if (oldDoc) {
                       requireUser("brianh");
                   }
               }
           }`
       }
   }
}


Here's the data on the server

curl -X GET localhost:4985/bsg_sync/brianh

{"_id":"brianh","_rev":"297-51800495-1cfc-412e-88cd-e456803c7e34","mySchedule":["session:6696","session:6232","session:6370","session:5058","session:5314"],"type":"profile"}

Another item should be added to the list here but is not.

-- 
You received this message because you are subscribed to the Google Groups 
"Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mobile-couchbase/2b40ddb2-ccd2-4105-9b0c-222e76d196e6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to