Skip to content
This repository has been archived by the owner on Apr 20, 2019. It is now read-only.

Commit

Permalink
Merge pull request #13 from hapijs/hapi8
Browse files Browse the repository at this point in the history
hapi 8. Closes #12
  • Loading branch information
dannycoates committed Dec 2, 2014
2 parents d436bb6 + 2d82caa commit 218dff5
Show file tree
Hide file tree
Showing 5 changed files with 646 additions and 630 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
test:
@node node_modules/lab/bin/lab
@node node_modules/lab/bin/lab -a code
test-cov:
@node node_modules/lab/bin/lab -t 100
@node node_modules/lab/bin/lab -a code -t 100
test-cov-html:
@node node_modules/lab/bin/lab -r html -o coverage.html
@node node_modules/lab/bin/lab -a code -r html -o coverage.html

.PHONY: test test-cov test-cov-html

32 changes: 21 additions & 11 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ var Hawk = require('hawk');
var internals = {};


exports.register = function (plugin, options, next) {
exports.register = function (server, options, next) {

plugin.auth.scheme('hawk', internals.hawk);
plugin.auth.scheme('bewit', internals.bewit);
server.auth.scheme('hawk', internals.hawk);
server.auth.scheme('bewit', internals.bewit);
return next();
};

Expand Down Expand Up @@ -54,25 +54,30 @@ internals.hawk = function (server, options) {
});
}

return reply(err, { credentials: credentials, artifacts: artifacts });
var result = { credentials: credentials, artifacts: artifacts };
if (err) {
return reply(err, null, result);
}

return reply.continue(result);
});
},
payload: function (request, next) {
payload: function (request, reply) {

if (!request.auth.artifacts.hash) {
return next(false);
return reply(Boom.unauthorized(null, 'Hawk')); // Missing
}

var plugin = request.plugins['hapi-auth-hawk'];
if (plugin &&
Hawk.server.authenticatePayloadHash(plugin.payloadHash, request.auth.artifacts)) {

return next();
return reply.continue();
}

return next(Boom.unauthorized('Payload is invalid'));
return reply(Boom.unauthorized('Payload is invalid'));
},
response: function (request, next) {
response: function (request, reply) {

var response = request.response;
var payloadHash = Hawk.crypto.initializePayloadHash(request.auth.credentials.algorithm, response.headers['content-type']);
Expand All @@ -91,7 +96,7 @@ internals.hawk = function (server, options) {
request.raw.res.addTrailers({ 'server-authorization': header });
});

return next();
return reply.continue();
}
};

Expand All @@ -112,7 +117,12 @@ internals.bewit = function (server, options) {

Hawk.server.authenticateBewit(request.raw.req, settings.getCredentialsFunc, settings.hawk, function (err, credentials, bewit) {

return reply(err, { credentials: credentials, artifacts: bewit });
var result = { credentials: credentials, artifacts: bewit };
if (err) {
return reply(err, null, result);
}

return reply.continue(result);
});
}
};
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"name": "hapi-auth-hawk",
"description": "Hawk authentication plugin",
"version": "1.1.1",
"author": "Eran Hammer <[email protected]> (http://hueniverse.com)",
"version": "2.0.0",
"repository": "git://github.com/hapijs/hapi-auth-hawk",
"main": "index",
"keywords": [
Expand All @@ -13,19 +12,20 @@
"bewit"
],
"engines": {
"node": ">=0.10.30"
"node": ">=0.10.33"
},
"dependencies": {
"boom": "2.x.x",
"hoek": "2.x.x",
"hawk": "2.x.x"
},
"peerDependencies": {
"hapi": ">=2.x.x"
"hapi": ">=8.x.x"
},
"devDependencies": {
"hapi": "6.x.x",
"lab": "3.x.x"
"code": "1.x.x",
"hapi": "8.x.x",
"lab": "5.x.x"
},
"scripts": {
"test": "make test-cov"
Expand Down
Loading

0 comments on commit 218dff5

Please sign in to comment.