Hi @Vinay,

CBL Android is not able to share cookie store, so an application needs to 
set cookie manually as you already done.

After 1.0.3/1.0.4 release, we reviewed how to set cookie from PhoneGap or 
REST API. We realized that headers item should be in the source or target 
item. See updated documentation for REST API _replicate 
(http://developer.couchbase.com/mobile/develop/references/couchbase-lite/rest-api/server/post-replicate/index.html#example)

So your JavaScript code should be like followings.
var syncDefinitionPush = {
     source: "budgetappdb",
     target: {
        headers: {
           Cookie: "SyncGatewaySession=" + config.user.sessionId
        },
        url: REMOTE_SYNC_URL
     },
     continuous: true
   };

var syncDefinitionPull = {
     target: "budgetappdb",
     
     source: {
       headers: {
          Cookie: "SyncGatewaySession=" + config.user.sessionId
       },
       url: REMOTE_SYNC_URL
     },
     continuous: true
   };

I hope this helps you.

Thanks,
Hideki

On Friday, May 1, 2015 at 4:14:43 AM UTC-7, Vinay Bhinde wrote:
>
> Hello All,
>
> I had a fully functional sync working with hybrid application on android 
> and ios and cblite phonegap plugin. I use custom authentication for 
> registering users with sync gateway .My app server returns me the cookie in 
> setCookie header and then while performing replication i was manually 
> setting the cookie header as follows :
>
> var syncDefinitionPush = {
>      source: "budgetappdb",
>      headers: {
>        Cookie: "SyncGatewaySession=" + config.user.sessionId
>      },
>      target: {
>        url: REMOTE_SYNC_URL
>      },
>      continuous: true
>    };
>
>
> var syncDefinitionPull = {
>      target: "budgetappdb",
>      headers: {
>        Cookie: "SyncGatewaySession=" + config.user.sessionId
>      },
>      source: {
>        url: REMOTE_SYNC_URL
>      },
>      continuous: true
>    };
>
> While in normal scenarios when your sync gateway and your app server 
> reside on the same domain then all the http requests should by default have 
> a cookie header set once the app server has sent a setCookie header in 
> response while performing custom authentication. But in case of cblite 
> replication calls being made internally by cb lite to sync gateway, it 
> didnt use the cookies and i was getting a 401 error while replicating on 
> sync gateway. Hence i had to manually set the cookie header while  starting 
> the replication process.
>
> All above was specifically needed on android. cblite on iOS automatically 
> uses the cookie to all subsequent calls made to sync_gateway after 
> authenticating with my app server.
>
> The main issue is that this stuff used to work on android with cblite 
> plugin version 1.0.3. But recently  significant improvements were made in 
> view indexing in android 1.0.4 and the build was given to us by one the 
> team members. So we updated the plugin version to 1.0.4.Below is the thread 
> where you can find the discussion and link to new plugin
>
> Plugin download link - 
> http://cbfs-ext.hq.couchbase.com/builds/Couchbase-Lite-PhoneGap-Plugin_1.0.4-47-63.zip
>  Discussion link - 
> https://groups.google.com/forum/#!topic/mobile-couchbase/urIqcOocmq4
>
> *The consequence was that now again cblite gets a 401 error on sync 
> gateway while performing replication. Even though i have set custom cookie 
> header while replicating still i guess somewhere in this new build the 
> header is not being set and hence cookie is not being sent when cblite 
> calls SG. Plus there is no way like in native API to setCookie so right now 
> my sync does not work at all specially in android !*
>
> Any help how do i force cblite to use the SyncGatewaySession cookie when 
> it makes http requests to SG for pull and push ?
>

-- 
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/759e97f5-c05c-4547-bb75-8e4c35bc7b84%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to