Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ArangoDB auth plugin #85

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions examples/authfs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"use strict";

var jsDAV = require("./../lib/jsdav");
jsDAV.debugMode = true;

var jsDAV_Locks_Backend_FS = require("./../lib/DAV/plugins/locks/fs");
var authBackend = require("./../lib/DAV/plugins/auth/arango");
var authPlugin = require("./../lib/DAV/plugins/auth");
var Db = require("./../lib/shared/backends/arango");

Db.getConnection("http://127.0.0.1:8529/users", function(err, db) {
if (err) throw err;

var arangoDB = authBackend.new(db);

jsDAV.createServer({
node: __dirname + "/../test/assets",
authBackend: arangoDB,
locksBackend: jsDAV_Locks_Backend_FS.new(__dirname + "/../test/assets"),
realm: "jsDAV",
plugins: [authPlugin]
}, 8000);
});
29 changes: 29 additions & 0 deletions lib/DAV/plugins/auth/arango.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"use strict";

var jsDAV_Auth_Backend_AbstractDigest = require("./abstractDigest");

/**
* This is an authentication backend that uses the arango database to manage passwords.
*/
var jsDAV_Auth_Backend_Arango = module.exports = jsDAV_Auth_Backend_AbstractDigest.extend({
initialize: function (db) {
jsDAV_Auth_Backend_AbstractDigest.initialize.call(this);
this.db = db;
},

/**
* Returns a users' information
*
* @param {string} realm
* @param {string} username
* @return {string}
*/
getDigestHash: function (realm, username, cbdigest) {
this.db.simple.first({username:username,realm:realm})
.then(function(ret){
cbdigest(null,ret && ret.document && ret.document.password);
},function(err){
return cbdigest(err);
});
}
});
10 changes: 10 additions & 0 deletions lib/shared/backends/arango.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
var arango = require("arango");

/* Example: getConnection("http://127.0.0.1:8529/users",clbk); */
exports.getConnection = function(connStr, callback) {
try {
callback(null,new arango.Connection(connStr));
} catch (err) {
callback(err);
}
};
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"dbox": "~0.5.6",
"redis": "~0.8.2",
"mongodb": "~1.2.12",
"gnu-tools": "0.0.x"
"gnu-tools": "0.0.x",
"arango": "git://github.com/kaerus-component/arango.git#master"
},
"licenses": [{
"type": "The MIT License",
Expand Down