Couchbase lite ios with session cookie


#1

Hi,

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.setAuthorizer(auth);
	replicator.getHeaders().put("Cookie", cookieName + "=" + cookieValue);

Thanks,
Yuzkan


#2

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.


#3

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


#4

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,
Yuzkan


#5

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.

https://groups.google.com/forum/?fromgroups#!forum/mobile-couchbase


#6

Thanks, I will.


#7

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?

Thanks


#8

Have you tried the -setCookieNamed: method on CBLReplication?