Custom Authentication example using Phonegap plugin?

184 views
Skip to first unread message

Federico Hernandez

unread,
Dec 16, 2014, 6:14:27 PM12/16/14
to mobile-c...@googlegroups.com
Hi everybody,

I've used the phonegap plugin to create a mobile app. 

Now, I'm trying to to perform a custom authentication to the Sync Manager. To do so, I've added a user into the Sync Manager and then created a session. I copied the session_id and cookie_name to create the cookie in the mobile app. However, when the app tries to connect to the Sync Manager, the app gets a 401 Login Required. If I do the same using the GUEST user, I can push and retrieve documents from the Sync Manager.

Does anybody have a good example of how to do a Custom Authentication? If not, can anybody point me in the right direction?

Thanks in advance,

Jens Alfke

unread,
Dec 16, 2014, 7:15:53 PM12/16/14
to mobile-c...@googlegroups.com

On Dec 16, 2014, at 3:14 PM, Federico Hernandez <fede.he...@gmail.com> wrote:

I've used the phonegap plugin to create a mobile app. 

Which platform? It's important to specify this when you ask questions.

—Jens

Federico Hernandez

unread,
Dec 17, 2014, 9:19:53 AM12/17/14
to mobile-c...@googlegroups.com
I'm using iOS, but then we'll have to do the same for Android.

Federico Hernandez

unread,
Dec 17, 2014, 9:38:30 AM12/17/14
to mobile-c...@googlegroups.com
I'm using coax library as I saw in the github examples, but I don't know how to set up the cookie once I get it from the my app server. The app server is the one in charge of creating the session into the sync manager.

Is there any way to perform a custom authentication using phonegap and coax? I haven't found any example, nor a document to do that. 

J. Chris Anderson

unread,
Dec 17, 2014, 6:09:07 PM12/17/14
to mobile-c...@googlegroups.com


On Wednesday, December 17, 2014 6:38:30 AM UTC-8, Federico Hernandez wrote:

Is there any way to perform a custom authentication using phonegap and coax? I haven't found any example, nor a document to do that. 

 
I think you are right we are missing a way to call setCookie. I've filed an issue here: https://github.com/couchbase/couchbase-lite-java-core/issues/360

For now the workaround would be to add a new method to our PhoneGap plugin that calls setCookie as documented here. 

Chris

Federico Hernandez

unread,
Dec 18, 2014, 7:35:11 AM12/18/14
to mobile-c...@googlegroups.com
Thanks Chris for the answer. 

Dominique Legault

unread,
Dec 18, 2014, 12:09:12 PM12/18/14
to mobile-c...@googlegroups.com
The way I do it is to use basic auth on the url like so:
var url = REMOTE_SYNC_PROTOCOL + encodeURIComponent( window.config.user.name ) + ":" + encodeURIComponent( window.config.user.password ) + "@" + REMOTE_SYNC_SERVER + ":" + REMOTE_SYNC_PORT + "/";
You still have to create the session in the sync gateway first though.

Federico Hernandez

unread,
Dec 18, 2014, 2:45:54 PM12/18/14
to mobile-c...@googlegroups.com


On Thursday, December 18, 2014 2:09:12 PM UTC-3, Dominique Legault wrote:
The way I do it is to use basic auth on the url like so:
var url = REMOTE_SYNC_PROTOCOL + encodeURIComponent( window.config.user.name ) + ":" + encodeURIComponent( window.config.user.password ) + "@" + REMOTE_SYNC_SERVER + ":" + REMOTE_SYNC_PORT + "/";
You still have to create the session in the sync gateway first though.


Thanks Dominique. I'll try it out.

Preethi SrinivasaMurthy

unread,
Apr 2, 2016, 1:55:55 AM4/2/16
to Couchbase Mobile

Hi there,

I have a question in the SyncGateway configserver.json file, are we supposed to have all users who use the mobile device login entered? Is it safe to enter plain text password in a json file on a server that is facing the public internet?

"users": {
"ravi": {
"disabled" : false,
"password": "ravi@123",
"admin_channels":["*"] 

Jens Alfke

unread,
Apr 4, 2016, 1:20:14 PM4/4/16
to mobile-c...@googlegroups.com

On Apr 1, 2016, at 10:55 PM, Preethi SrinivasaMurthy <preeth...@gmail.com> wrote:

I have a question in the SyncGateway configserver.json file, are we supposed to have all users who use the mobile device login entered? 

No. The list of users in the config file is just a bootstrap for setting up a new database, or for testing. You don’t need to put anything in there at all. You should be using the admin REST API to create and manage user accounts.

—Jens

Preethi SrinivasaMurthy

unread,
May 5, 2016, 1:01:39 AM5/5/16
to Couchbase Mobile
Is this still an issue? We are using phonegap/cordova(6.0.1) with coax(version 0.4.2) on android tablet. We are using custom authentication. Are we supposed to set the session id or cookie on the client mobile app? We are trying to get the login authentication working so that we can move on to authorization using channels.

Do we have this method available in phonegap plugin now?
Reply all
Reply to author
Forward
0 new messages