Skip to content

Commit

Permalink
added cookie strategy for session management for #8
Browse files Browse the repository at this point in the history
  • Loading branch information
travi committed Mar 7, 2016
1 parent 7c6748a commit 6b8d8b2
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
8 changes: 7 additions & 1 deletion lib/auth/strategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,16 @@ exports.register = function (server, options, next) {
isSecure: secure
});

server.auth.strategy('session', 'cookie', {
password: process.env.AUTH_COOKIE_ENCRYPTION_PASSWORD,
redirectTo: '/login',
isSecure: secure
});

next();
};

exports.register.attributes = {
name: 'authentication-strategy',
dependencies: 'bell'
dependencies: ['bell', 'hapi-auth-cookie']
};
1 change: 1 addition & 0 deletions lib/manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ module.exports = {
{plugin: './api/auth/strategy'},
{plugin: './api/router'},
{plugin: 'bell'},
{plugin: 'hapi-auth-cookie'},
{
plugin: {
register: './auth/strategy',
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"good-console": "5.3.1",
"halacious": "3.5.3",
"hapi": "13.0.0",
"hapi-auth-cookie": "6.1.1",
"hapi-mustache": "0.0.1",
"hapi-swaggered": "2.6.0",
"hapi-swaggered-ui": "2.3.1",
Expand Down
9 changes: 7 additions & 2 deletions test/unit/auth/strategy-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ suite('authentication strategy', () => {
test('that the plugin is defined', () => {
assert.equals(auth.register.attributes, {
name: 'authentication-strategy',
dependencies: 'bell'
dependencies: ['bell', 'hapi-auth-cookie']
});
});

test('that bell is registered as a strategy', () => {
test('that the authentication and session strategies are registered', () => {
const
next = sinon.spy(),
strategy = sinon.spy(),
Expand All @@ -43,6 +43,11 @@ suite('authentication strategy', () => {
forceHttps: secure,
isSecure: secure
});
assert.calledWith(strategy, 'session', 'cookie', {
password,
redirectTo: '/login',
isSecure: secure
});
assert.calledOnce(next);
});
});

0 comments on commit 6b8d8b2

Please sign in to comment.