Skip to content

Commit

Permalink
Add a clone utilities 'cloneextend'
Browse files Browse the repository at this point in the history
  • Loading branch information
hgarcia committed Jan 3, 2013
1 parent abbdb6d commit b921826
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/private-public-key.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use strict";

var crypto = require('crypto');
var u = require('cloneextend');

function isValidToken(secretKey, dateTime, token) {
var hash = crypto.createHmac('sha1', secretKey)
Expand Down Expand Up @@ -36,6 +36,7 @@ module.exports = function (accountStore, options) {
options = getDefaultOptions();
}
req.authorized = false;
req.currentAccount = null;
if (!accountStore || !accountStore.get ||
(!hasHeaders(req.headers, options))) {
return next();
Expand All @@ -46,6 +47,7 @@ module.exports = function (accountStore, options) {
account.secretKey
) {
req.authorized = isValidToken(account.secretKey, req.headers[options.dateTime], req.headers[options.token]);
req.currentAccount = u.clone(account);
}
next();
});
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
"type": "git",
"url": "git://github.com/hgarcia/who-are-you.git"
},
"dependencies": {
"cloneextend": "0.0.3"
},
"devDependencies": {
"mocha": "1.7.4",
"should": "1.2.1",
Expand Down
1 change: 1 addition & 0 deletions tests/ppk.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ describe("privatePublicKey(store, custom)", function () {
var req = getCustomRequest();
handler(req, {}, function () {
req.authorized.should.be.ok;
req.currentAccount.secretKey.should.eql("hjk876AXk90");
});
});
});
Expand Down

0 comments on commit b921826

Please sign in to comment.