0

I have a CouchDB instance running and I am trying to use cookie authentication to connect from an Ember application.

From the command line I can successfully authenticate using:

curl -vX POST $HOST/_session -H 'Content-Type: application/json' -d '{ "name": "will", "password": "secret" }'

This generates the following request:

POST /_session HTTP/1.1
User-Agent: curl/7.32.0
Host: 127.0.0.1:5984
Accept: */*
Content-Type: application/json
Content-Length: 40

My javascript for the same operation is:

$.ajax( {
  type: 'POST',
  url: "%@/_session".fmt( App.Host ),
  data: JSON.stringify( { user: $('#username').val(), password: $('#password').val() } ),
  dataType: 'json',
  contentType: 'application/json'
} )

This creates the appropriate request:

Accept:application/json, text/javascript, */*; q=0.01
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8,fr;q=0.6
Connection:keep-alive
Content-Length:35
Content-Type:application/json
Host:localhost:5984
Origin:http://localhost
Referer:http://localhost/~will/howlin-wolf/www/
User-Agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.116 Safari/537.36

The response though is 401, unauthorized.

I get the same result then using x-www-form-urlencoded information. The curl request works:

curl -vX POST $HOST/_session -d 'name=will&password=secret'

The jQuery does not:

$.ajax( {
  type: 'POST',
  url: "%@/_session".fmt( App.Host ),
  data: "user=%@&password=%@".fmt( $('#username').val(), $('#password').val() )
} )
dysbulic
  • 3,005
  • 2
  • 28
  • 48

1 Answers1

0

I was using user in the jQuery requests when it should have been name.

dysbulic
  • 3,005
  • 2
  • 28
  • 48