Username and password authentication on couchbase sync gateway using JQuery

1,071 views
Skip to first unread message

Anurag Ghosh

unread,
Dec 3, 2013, 11:53:42 AM12/3/13
to mobile-c...@googlegroups.com
Hi,

Please help me on this.

I am trying to connect to couchbase sync gateway using below ajax call with username and password but couldn't get any success. This username and password is already configured in the couchbase server.

However authentication is working fine when doing Ajax call for servlet and servlet in turn is connecting to couchbase sync gateway with the same username and password.

It seems something is missing in the below ajax call. 
Can anyone please help in this username and password authentication on couchbase sync gateway using JQuery?

I am using below code:

$.ajax({
        
            url: "http://<ip address:port number>/soyassist/_all_docs?include_docs=true",
            type: 'GET',
            username: "anurag",
            password: "anurag", 
            dataType: 'jsonp',
            contentType: 'application/json',
            mimeType: 'application/json',
            complete: function(data) {
                
                alert(data); 
                alert(JSON.stringify(data));
                //alert(data.total_rows);
            },
            error:function(data,status,er) {
                alert("ERROR GETTING DATA FROM SERVER!");
               // localread();
            }
        });

Jens Alfke

unread,
Dec 3, 2013, 12:04:55 PM12/3/13
to mobile-c...@googlegroups.com

On Dec 3, 2013, at 8:53 AM, Anurag Ghosh <anurag.g...@gmail.com> wrote:

I am trying to connect to couchbase sync gateway using below ajax call with username and password but couldn't get any success. This username and password is already configured in the couchbase server.

The Sync Gateway doesn’t use Couchbase Server accounts; it manages its own. (Couchbase Server isn’t meant to directly face end users, so its accounts are for server admins. The gateway does manage end-user accounts.)

See the Gateway documentation for the API for creating and managing user accounts.

—Jens

Anurag Ghosh

unread,
Dec 3, 2013, 12:08:48 PM12/3/13
to mobile-c...@googlegroups.com
Hi,

Thanks for the reply.

I have configured the user credentials in sync gateway as well, still the below ajax call not working. Does this call is correct or it should be done in a different way.

Many Thanks.

-Anurag

Jens Alfke

unread,
Dec 3, 2013, 12:13:15 PM12/3/13
to mobile-c...@googlegroups.com

On Dec 3, 2013, at 9:08 AM, Anurag Ghosh <anurag.g...@gmail.com> wrote:

I have configured the user credentials in sync gateway as well, still the below ajax call not working. Does this call is correct or it should be done in a different way.

It looks like a JQuery call? I don’t know much about JQuery so I can’t tell what kind of HTTP request it’s actually sending. It should be using HTTP Basic auth. Alternatively you can POST once to /db/_session to set a login session cookie — see the API docs for details.

—Jens

J. Chris Anderson

unread,
Dec 3, 2013, 10:38:00 PM12/3/13
to mobile-c...@googlegroups.com
This looks like it may be related to CORS support. What happens when you host the HTML that loads your javascript, directly as an attachment in Sync Gateway?

Alternatively, you could try implementing CORS: https://github.com/couchbase/sync_gateway/issues/115
Reply all
Reply to author
Forward
0 new messages