diff options
author | Filipe David Borba Manana <fdmanana@apache.org> | 2010-08-04 10:36:35 +0000 |
---|---|---|
committer | Filipe David Borba Manana <fdmanana@apache.org> | 2010-08-04 10:36:35 +0000 |
commit | aea47cc3831fd7b5a8c926557ad79cffbe9639ef (patch) | |
tree | bf2ec65b7f4630b75aa0a0b8c3957d2c868fd100 | |
parent | 495c20b9856b2abcbdc5a4620d6b4304dcafd70d (diff) |
Allow POSTing of a JSON object to /_session/ for login.
Closes COUCHDB-842, patch by Jonathan D. Knezek.
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@982200 13f79535-47bb-0310-9956-ffa450edef68
-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, |