couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject [2/13] git commit: An auth handler based on a shared secret with a subprocess
Date Wed, 13 Feb 2013 13:17:15 GMT
An auth handler based on a shared secret with a subprocess


Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/7df7d976
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/7df7d976
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/7df7d976

Branch: refs/heads/nodejs_couchdb
Commit: 7df7d9764e4e4fc9676f266490560a252cca141f
Parents: 1166f28
Author: Jason Smith (work) <jhs@iriscouch.com>
Authored: Tue Feb 12 11:27:23 2013 +0000
Committer: Jason Smith (work) <jhs@iriscouch.com>
Committed: Tue Feb 12 11:27:23 2013 +0000

----------------------------------------------------------------------
 src/couchdb/couch_httpd_auth.erl |   30 ++++++++++++++++++++++++++++++
 1 files changed, 30 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/7df7d976/src/couchdb/couch_httpd_auth.erl
----------------------------------------------------------------------
diff --git a/src/couchdb/couch_httpd_auth.erl b/src/couchdb/couch_httpd_auth.erl
index a967e09..b2b7056 100644
--- a/src/couchdb/couch_httpd_auth.erl
+++ b/src/couchdb/couch_httpd_auth.erl
@@ -15,6 +15,7 @@
 
 -export([default_authentication_handler/1,special_test_authentication_handler/1]).
 -export([cookie_authentication_handler/1]).
+-export([nodejs_authentication_handler/1]).
 -export([null_authentication_handler/1]).
 -export([proxy_authentification_handler/1]).
 -export([cookie_auth_header/2]).
@@ -92,6 +93,35 @@ default_authentication_handler(Req) ->
         end
     end.
 
+
+nodejs_authentication_handler(Req) ->
+    case os:getenv("COUCHDB_NODEJS_PASSWORD") of
+        false ->
+            Req;
+        Password ->
+            nodejs_authentication_handler(Req, Password)
+    end.
+
+nodejs_authentication_handler(Req, Password) ->
+    case couch_httpd:header_value(Req, "Authorization") of
+        "Basic " ++ Base64Value ->
+            PwBin = ?l2b(Password),
+            Given = base64:decode(Base64Value),
+            nodejs_authentication_handler(Req, PwBin, Given);
+        _ ->
+            Req
+    end.
+
+nodejs_authentication_handler(Req, Password, Given) ->
+    case Given of
+        <<"_nodejs:", Password/binary>> ->
+            User = <<"_nodejs">>,
+            Req#httpd{user_ctx=#user_ctx{name=User, roles=[<<"_admin">>]}};
+        _ ->
+            Req
+    end.
+
+
 null_authentication_handler(Req) ->
     Req#httpd{user_ctx=#user_ctx{roles=[<<"_admin">>]}}.
 


Mime
View raw message