Couchbase lite ios with session cookie



I need a bit of help how to run a replication using sync gateway cookie/sessionID.
I’m setting the cookie like this:

[self.replication.headers setValue:value forKey:@"Cookie"];

But the cookie doesn’t get sent.

For Android I was able to run the synchronization with the following code:

Authorizer auth = new Authorizer() { @Override public boolean usesCookieBasedLogin() { return true; } };
	replicator.getHeaders().put("Cookie", cookieName + "=" + cookieValue);



The cookie will get sent automatically if you’ve logged into the Gateway by issuing a POST to /db/_session.

Also, make sure you actually need to use session-based logins. You should only need to if you’ve set up custom authentication on the server side; otherwise the default HTTP Basic auth works fine.


Also: If you do find you need to add a session cookie explicitly, the right API to do that is NSHTTPCookieStorage.


Thanks, for the quick response.

I do need to use the session based login because the authentication happens on server.
Is there an example where I can look to for the session based login?

Thanks again,


Could you post to the mailing list? It’s a lot easier to follow than this web-forum, and more people will see the question. Thanks.!forum/mobile-couchbase


Thanks, I will.


Getting ‘401 unauthorized’ on sync gateway. I did set the cookie in NSHTTPCookieStorage and replication.headers.

I don’t see HTTP headers in the web proxy, any thoughts?



Have you tried the -setCookieNamed: method on CBLReplication?