diff options
-rw-r--r-- | THANKS | 1 | ||||
-rw-r--r-- | share/www/script/test/cookie_auth.js | 12 | ||||
-rw-r--r-- | src/couchdb/couch_httpd_auth.erl | 6 |
3 files changed, 18 insertions, 1 deletions
@@ -64,5 +64,6 @@ suggesting improvements or submitting changes. Some of these people are: * Caleb Land <caleb.land@gmail.com> * Juhani Ränkimies <juhani@juranki.com> * Kev Jackson <foamdino@gmail.com> + * Jonathan D. Knezek <jdknezek@gmail.com> For a list of authors see the `AUTHORS` file. diff --git a/share/www/script/test/cookie_auth.js b/share/www/script/test/cookie_auth.js index 68ec882d..e919ed02 100644 --- a/share/www/script/test/cookie_auth.js +++ b/share/www/script/test/cookie_auth.js @@ -104,6 +104,18 @@ couchTests.cookie_auth = function(debug) { T(CouchDB.login('Jason Davies', password).ok); T(CouchDB.session().userCtx.name == 'Jason Davies'); + // JSON login works + xhr = CouchDB.request("POST", "/_session", { + headers: {"Content-Type": "application/json"}, + body: JSON.stringify({ + name: 'Jason Davies', + password: password + }) + }); + + T(JSON.parse(xhr.responseText).ok); + T(CouchDB.session().userCtx.name == 'Jason Davies'); + // update one's own credentials document jasonUserDoc.foo=2; T(usersDb.save(jasonUserDoc).ok); diff --git a/src/couchdb/couch_httpd_auth.erl b/src/couchdb/couch_httpd_auth.erl index 7023e7f3..f76898e1 100644 --- a/src/couchdb/couch_httpd_auth.erl +++ b/src/couchdb/couch_httpd_auth.erl @@ -247,13 +247,17 @@ ensure_cookie_auth_secret() -> % session handlers % Login handler with user db -% TODO this should also allow a JSON POST handle_session_req(#httpd{method='POST', mochi_req=MochiReq}=Req) -> ReqBody = MochiReq:recv_body(), Form = case MochiReq:get_primary_header_value("content-type") of % content type should be json "application/x-www-form-urlencoded" ++ _ -> mochiweb_util:parse_qs(ReqBody); + "application/json" ++ _ -> + {Pairs} = ?JSON_DECODE(ReqBody), + lists:map(fun({Key, Value}) -> + {?b2l(Key), ?b2l(Value)} + end, Pairs); _ -> [] end, |