Phonegap and custom auth for replication

64 views
Skip to first unread message

João Agostinho

unread,
Nov 10, 2014, 7:12:46 AM11/10/14
to mobile-c...@googlegroups.com
Greetings,

I'm trying to setup the synchronization between a device's local DB and the my server's DB using phonegap and custom authentication, but im having difficulties figuring out the authentication.

I've setup an API on my server that uses the gateway's admin api to get a session token as described in the custom(indirect) section of this page http://developer.couchbase.com/mobile/develop/guides/sync-gateway/administering-sync-gateway/authenticating-users/index.html and im returning the session token to my phonegap app but i cant figure out how to pass it to cblite either before or when calling "_replicate" on cblite so that the replication doesn't fail with an 401. The phonegap example app uses facebook not custom and i haven't been able to find any documentation on how to do it for custom in the cblite REST api.

Can you point me to an example or documentation on this?

Jens Alfke

unread,
Nov 10, 2014, 1:33:56 PM11/10/14
to mobile-c...@googlegroups.com
On Nov 10, 2014, at 4:12 AM, João Agostinho <joa...@gmail.com> wrote:

im returning the session token to my phonegap app but i cant figure out how to pass it to cblite

The cleanest way is to configure your server so that the API endpoint you use for your custom auth has the same hostname and port as the SG. (You'll need to use some kind of proxy or URL rewriter to do that, like nginx or Apache.) Then your custom auth endpoint can just return a Set-Cookie: header with the session cookie, and the client will automatically start using it for calls to the SG.

If you can't configure the server that way, then on the client you can explicitly force the replicator to send the cookie by adding a "Cookie" property to a "headers" object in your replication config.

—Jens

João Agostinho

unread,
Nov 11, 2014, 6:40:48 AM11/11/14
to mobile-c...@googlegroups.com
The problem turned out to be an old version of the plugin, for some reason the command 'cordova plugin add com.couchbase.lite.phonegap' was (or is) installing an old version of the plugin 1.0.0-BETA which does not support the "headers" object which i actually had already tried to use. After changing to the newerr version with 'phonegap local plugin add https://github.com/couchbaselabs/Couchbase-Lite-PhoneGap-Plugin.git' it works fine.

Jens Alfke

unread,
Nov 11, 2014, 12:02:38 PM11/11/14
to mobile-c...@googlegroups.com

> On Nov 11, 2014, at 3:40 AM, João Agostinho <joa...@gmail.com> wrote:
>
> The problem turned out to be an old version of the plugin, for some reason the command 'cordova plugin add com.couchbase.lite.phonegap' was (or is) installing an old version of the plugin 1.0.0-BETA

That sounds pretty bad; we really don't want people running with old versions of Couchbase Lite, especially pre-1.0!
I've alerted the responsible parties so we'll see about getting this fixed. Thanks for letting us know.

—Jens

J. Chris Anderson

unread,
Dec 5, 2014, 12:12:04 PM12/5/14
to mobile-c...@googlegroups.com


On Tuesday, November 11, 2014 9:02:38 AM UTC-8, Jens Alfke wrote:

> On Nov 11, 2014, at 3:40 AM, João Agostinho wrote:
>
> The problem turned out to be an old version of the plugin, for some reason the command 'cordova plugin add com.couchbase.lite.phonegap' was (or is) installing an old version of the plugin 1.0.0-BETA

That sounds pretty bad; we really don't want people running with old versions of Couchbase Lite, especially pre-1.0!
I've alerted the responsible parties so we'll see about getting this fixed. Thanks for letting us know.

I just tested an installation installed via

cordova plugin add com.couchbase.lite.phonegap

and everything is clean. So it's been update/fixed (I think we did a release since this thread) -- hopefully it works for you too.

Chris

 
Reply all
Reply to author
Forward
0 new messages