Sync Gateway Authentication

We are using phonegap/cordova application running on Android tablet. We post the login credentials(Client/tablet) to an existing authentication service that connects to syncgateway admin port and creates a user and obtains a session from sync gateway. Now how do I use this session/cookie from my client requests so that we can get the channel set up working properly for particular users. Also what does this below statement mean, this is from the Couchbase Sync Gateway Documentation. What does your app’s API mean in this.

Subsequent client requests to the gateway will now include the session in a cookie, which the gateway will recognize. For the cookie to be recognized, your site must be configured so that your app’s API and the gateway appear on the same public host name and port.

It will be very helpful if you can point me in the direction.

Thank you all for all the help!

To use the session cookie that your existing authentication service obtained, you’ll need to return that cookie to the client, and set that cookie on subsequent requests against the Sync Gateway API.

What the doc excerpt is trying to say is that if your authentication service is returning a response that includes a Set-Cookie header for the Sync Gateway session value, your client HTTP library will usually by default associate that cookie with the domain your authentication service is running on, and not the Sync Gateway domain (unless it’s the same domain). If that’s the case, your client may have to do some additional work to extract the cookie and use it when calling Sync Gateway.

Thank you so much for the response. We have both Authentication service and Sync Gateway running on the same domain/host. But does the port matter? Authentication service runs on Jboss server port 8080 while sync gateway runs on port 4984/4985.

Also within phonegap application, where do I set the cookie? Is it within the push and pull calls?
something like this?

push = {
source : appDbName,
headers: {
Cookie: sessionReturnedFromSyncGateway
},
target : remote,
continuous : true,
whatfunc : “pushVar”
}, pull = {
target : appDbName,
headers: {
Cookie: sessionReturnedFromSyncGateway
},
source : remote,
continuous : true,
whatfunc : “pullVar”
},