Phonegap Plugin examples with basic auth


#1

Integrating the Android Couchbase Mobile sdk is pretty easy. You can find great example (ToDo Lite) and test different authentication (facebook, basic and so on), replication, etc…

With phonegap seems more complicated. There is not enough documentation (or I could not find it) and understand the example becomes a complex task. I want to develop a phonegap app (ios and android support) with basic authentication. Is there any example using basic authentication (user/pass)? Any tutorial to start learning the phonegap plugin? ToDo Lite just has facebook auth.

Thanks!


#2

Hey @javilin,

The following isn’t PhoneGap, but it still operates on Apache Cordova:

More importantly, you’ll want to take a look at how it uses the Couchbase Lite RESTful APIs found here:

http://developer.couchbase.com/mobile/develop/references/couchbase-lite/rest-api/index.html

Definitely start there and reach out if you have particular questions. That repository is a work in progress, but it will soon have authentication and replication included.

Best,


#3

Sorry about the lack of PhoneGap docs! We’re aware of it and hope to improve them.

With PhoneGap you use the REST API (which is 98% the same as the CouchDB REST API). To replicate you POST to /_replicate. To specify Basic auth you add the username and password to the server URL, like http://user:pass@server.com/dbname.


#4

Thanks @jens

Should I include any other header parameter (cookie, session id, etc) into the request header? is it just enough with the user and pass in the URL?


#5

Yes, if you’re just using basic auth to connect to the server.


#6

You can also checkout @jamiltz’s recent talk on building hybrid apps with Couchbase Lite: http://youtu.be/N8-tIaBVdOI


#7

thanks @zgramana the video helps us a lot but we still have doubts about basic auth. The slides/video shows the http request example schema for facebook and mentions place the user/pass into the URL.

Anyone has an example of the request for basic auth?
Anyone could tell us the step by step process for basic auth? For example:

  1. call Rest API /_session to get a validad session ID
  2. call Rest API /_replication with user/pass into the URL and session ID into the header.
  3. keep session ID until expires

In other hand, is there any repo for the video Todos example?
Thanks guys!


#8

I already explained everything you need to do for Basic auth. You add the username and password to the remote DB URL. That’s it. Period. No need to use _session (I don’t believe we even implement _session in CBL’s REST API; it’s only in Sync Gateway.)