Authentication fail handler not called when performing continuous sync replication in cordova app

62 views
Skip to first unread message

Vinay Bhinde

unread,
Jan 1, 2015, 2:42:29 AM1/1/15
to mobile-c...@googlegroups.com
I am using cblite on android and ios using cordova and i am having custom authentication for sync with gateway. I cannot find a way to call a specific function when my authentication with SG fails when triggering sync process. I need this because i have to go and get a new session in case if the cookie expires or is destroyed by any means.

Below is the code i use for syncing


I notice that there is a function authChallenge which should be called when auth fails but i tried reproducing it by not sending the cookie and calling _replicate, but still the handler does not get called.

Also i recently updated my plugin version from 1.0.0 beta to 1.0.2. Fun fact is the above function was called successfully when my authentication with SG failed in 1.0.0 but now in 1.0.2 it isn't called.

Some more bit of information that i am not able to figure out --> As  far as i know when i call trigger sync from my code it first initiates a push replication from cblite to SG and then pull replication from SG to cblite. Now what i am doing is that i am not sending cookies to purposely check what happens and on doing this as soon as i trigger sync the logs on SG show 401 Lo-gin required error which is perfect as i didn't send a cookie. But when i check my network requests on cblite client it shows _replicate request with a session id rep001 in response.

Why does it return a replication session id when SG is showing auth error. Should not it give me a error message in resoponse ?

Jens Alfke

unread,
Jan 1, 2015, 2:23:35 PM1/1/15
to mobile-c...@googlegroups.com
On Dec 31, 2014, at 11:42 PM, Vinay Bhinde <vin...@gmail.com> wrote:

As  far as i know when i call trigger sync from my code it first initiates a push replication from cblite to SG and then pull replication from SG to cblite.

Actually the push and pull run simultaneously.

Now what i am doing is that i am not sending cookies to purposely check what happens and on doing this as soon as i trigger sync the logs on SG show 401 Lo-gin required error which is perfect as i didn't send a cookie. But when i check my network requests on cblite client it shows _replicate request with a session id rep001 in response.

The "session" key in the JSON response is not an HTTP session cookie; it's an ID that represents the replication task internally. (The name is confusing, but we didn't make it up; it came from the CouchDB API.)

—Jens

Vinay Bhinde

unread,
Jan 1, 2015, 11:38:49 PM1/1/15
to mobile-c...@googlegroups.com

The "session" key in the JSON response is not an HTTP session cookie; it's an ID that represents the replication task internally. (The name is confusing, but we didn't make it up; it came from the CouchDB API.)

—Jens

Ok understood that thing. 

So now if the auth to SG fails, how i call my function to get a new cookie so that sync can continue ?

And any clue why does it work in 1.0.0 and not in 1.0.2 ? (i.e the authChallenge handler mentioned in my code)

Traun Leyden

unread,
Jan 8, 2015, 6:57:17 PM1/8/15
to mobile-c...@googlegroups.com

If it worked in 1.0.0 but does not work in 1.0.2, that's a regression bug.

Any chance you can enhance https://github.com/couchbaselabs/TodoLite-PhoneGap to have this feature and handle auth errors when connecting to sync gateway?

That way, we can easily reproduce and compare the behavior between iOS and Android.


--
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 mobile-couchba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mobile-couchbase/58b132fa-a6b2-4526-80df-a0ddbcad53b1%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages