Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hapi-auth-cookie

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hapi-auth-cookie - npm Package Compare versions

Comparing version 1.4.1 to 2.0.0-rc1

5

example/index.js

@@ -78,5 +78,6 @@ var Hapi = require('hapi');

var server = new Hapi.Server(8000);
var server = new Hapi.Server();
server.connect({ port: 8000 });
server.pack.register(require('../'), function (err) {
server.register(require('../'), function (err) {

@@ -83,0 +84,0 @@ var cache = server.cache('sessions', { expiresIn: 3 * 24 * 60 * 60 * 1000 });

19

lib/index.js

@@ -12,5 +12,5 @@ // Load modules

exports.register = function (plugin, options, next) {
exports.register = function (server, options, next) {
plugin.auth.scheme('cookie', internals.implementation);
server.auth.scheme('cookie', internals.implementation);
next();

@@ -41,3 +41,4 @@ };

isHttpOnly: settings.isHttpOnly !== false, // Defaults to true
clearInvalid: settings.clearInvalid
clearInvalid: settings.clearInvalid,
ignoreErrors: true
};

@@ -103,3 +104,3 @@

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

@@ -124,3 +125,3 @@

return reply(null, { credentials: session, artifacts: session });
return reply.continue({ credentials: session, artifacts: session });
}

@@ -144,3 +145,3 @@

return reply(null, { credentials: credentials || session, artifacts: session });
return reply.continue({ credentials: credentials || session, artifacts: session });
});

@@ -154,3 +155,3 @@ };

return reply(err, result);
return reply(err, null, result);
}

@@ -166,3 +167,3 @@

if (!redirectTo) {
return reply(err, result);
return reply(err, null, result);
}

@@ -182,3 +183,3 @@

return reply('You are being redirected...', result).redirect(uri);
return reply('You are being redirected...', null, result).redirect(uri);
};

@@ -185,0 +186,0 @@

{
"name": "hapi-auth-cookie",
"description": "Cookie authentication plugin",
"version": "1.4.1",
"version": "2.0.0-rc1",
"repository": "git://github.com/hapijs/hapi-auth-cookie",

@@ -22,7 +22,7 @@ "main": "index",

"peerDependencies": {
"hapi": ">=2.x.x"
"hapi": ">=8.x.x"
},
"devDependencies": {
"code": "1.x.x",
"hapi": "7.x.x",
"hapi": "8.x.x",
"lab": "5.x.x"

@@ -29,0 +29,0 @@ },

@@ -27,3 +27,4 @@ // Load modules

var server = new Hapi.Server();
server.pack.register(require('../'), function (err) {
server.connection();
server.register(require('../'), function (err) {

@@ -88,23 +89,25 @@ expect(err).to.not.exist();

var extraSchemePlugin = {
name: 'simpleTestAuth',
register: function (plugin, options, next) {
var extraSchemePlugin = function (plugin, options, next) {
var simpleTestSchema = function () {
var simpleTestSchema = function () {
return {
authenticate: function (request, reply) {
return {
authenticate: function (request, reply) {
return reply(null, { credentials: { test: 'valid' } });
}
};
return reply.continue({ credentials: { test: 'valid' } });
}
};
};
plugin.auth.scheme('simpleTest', simpleTestSchema);
return next();
}
plugin.auth.scheme('simpleTest', simpleTestSchema);
return next();
};
extraSchemePlugin.attributes = {
name: 'simpleTestAuth'
};
var server = new Hapi.Server();
server.pack.register(require('../'), function (err) {
server.connection();
server.register(require('../'), function (err) {

@@ -140,3 +143,3 @@ expect(err).to.not.exist();

server.pack.register(extraSchemePlugin, function (err) {
server.register(extraSchemePlugin, function (err) {

@@ -176,3 +179,4 @@ expect(err).to.not.exist();

var server = new Hapi.Server();
server.pack.register(require('../'), function (err) {
server.connection();
server.register(require('../'), function (err) {

@@ -238,3 +242,4 @@ expect(err).to.not.exist();

var server = new Hapi.Server();
server.pack.register(require('../'), function (err) {
server.connection();
server.register(require('../'), function (err) {

@@ -299,3 +304,4 @@ expect(err).to.not.exist();

var server = new Hapi.Server();
server.pack.register(require('../'), function (err) {
server.connection();
server.register(require('../'), function (err) {

@@ -359,3 +365,4 @@ expect(err).to.not.exist();

var server = new Hapi.Server();
server.pack.register(require('../'), function (err) {
server.connection();
server.register(require('../'), function (err) {

@@ -412,3 +419,4 @@ expect(err).to.not.exist();

var server = new Hapi.Server();
server.pack.register(require('../'), function (err) {
server.connection();
server.register(require('../'), function (err) {

@@ -465,3 +473,4 @@ expect(err).to.not.exist();

var server = new Hapi.Server();
server.pack.register(require('../'), function (err) {
server.connection();
server.register(require('../'), function (err) {

@@ -511,3 +520,4 @@ expect(err).to.not.exist();

var server = new Hapi.Server();
server.pack.register(require('../'), function (err) {
server.connection();
server.register(require('../'), function (err) {

@@ -569,3 +579,4 @@ expect(err).to.not.exist();

var server = new Hapi.Server();
server.pack.register(require('../'), function (err) {
server.connection();
server.register(require('../'), function (err) {

@@ -628,3 +639,4 @@ expect(err).to.not.exist();

var server = new Hapi.Server();
server.pack.register(require('../'), function (err) {
server.connection();
server.register(require('../'), function (err) {

@@ -683,3 +695,4 @@ expect(err).to.not.exist();

var server = new Hapi.Server();
server.pack.register(require('../'), function (err) {
server.connection();
server.register(require('../'), function (err) {

@@ -751,3 +764,4 @@ expect(err).to.not.exist();

var server = new Hapi.Server();
server.pack.register(require('../'), function (err) {
server.connection();
server.register(require('../'), function (err) {

@@ -792,3 +806,4 @@ expect(err).to.not.exist();

var server = new Hapi.Server();
server.pack.register(require('../'), function (err) {
server.connection();
server.register(require('../'), function (err) {

@@ -842,3 +857,4 @@ expect(err).to.not.exist();

var server = new Hapi.Server();
server.pack.register(require('../'), function (err) {
server.connection();
server.register(require('../'), function (err) {

@@ -883,3 +899,4 @@ expect(err).to.not.exist();

var server = new Hapi.Server();
server.pack.register(require('../'), function (err) {
server.connection();
server.register(require('../'), function (err) {

@@ -924,3 +941,4 @@ expect(err).to.not.exist();

var server = new Hapi.Server();
server.pack.register(require('../'), function (err) {
server.connection();
server.register(require('../'), function (err) {

@@ -968,3 +986,4 @@ expect(err).to.not.exist();

var server = new Hapi.Server();
server.pack.register(require('../'), function (err) {
server.connection();
server.register(require('../'), function (err) {

@@ -1018,3 +1037,4 @@ expect(err).to.not.exist();

var server = new Hapi.Server();
server.pack.register(require('../'), function (err) {
server.connection();
server.register(require('../'), function (err) {

@@ -1059,3 +1079,4 @@ expect(err).to.not.exist();

var server = new Hapi.Server();
server.pack.register(require('../'), function (err) {
server.connection();
server.register(require('../'), function (err) {

@@ -1100,3 +1121,4 @@ expect(err).to.not.exist();

var server = new Hapi.Server();
server.pack.register(require('../'), function (err) {
server.connection();
server.register(require('../'), function (err) {

@@ -1144,3 +1166,4 @@ expect(err).to.not.exist();

var server = new Hapi.Server();
server.pack.register(require('../'), function (err) {
server.connection();
server.register(require('../'), function (err) {

@@ -1198,3 +1221,4 @@ expect(err).to.not.exist();

var server = new Hapi.Server();
server.pack.register(require('../'), function (err) {
server.connection();
server.register(require('../'), function (err) {

@@ -1229,3 +1253,4 @@ expect(err).to.not.exist();

var server = new Hapi.Server();
server.pack.register(require('../'), function (err) {
server.connection();
server.register(require('../'), function (err) {

@@ -1268,3 +1293,4 @@ expect(err).to.not.exist();

var server = new Hapi.Server();
server.pack.register(require('../'), function (err) {
server.connection();
server.register(require('../'), function (err) {

@@ -1302,3 +1328,4 @@ expect(err).to.not.exist();

var server = new Hapi.Server();
server.pack.register(require('../'), function (err) {
server.connection();
server.register(require('../'), function (err) {

@@ -1333,3 +1360,4 @@ expect(err).to.not.exist();

var server = new Hapi.Server();
server.pack.register(require('../'), function (err) {
server.connection();
server.register(require('../'), function (err) {

@@ -1364,3 +1392,4 @@ expect(err).to.not.exist();

var server = new Hapi.Server();
server.pack.register(require('../'), function (err) {
server.connection();
server.register(require('../'), function (err) {

@@ -1395,3 +1424,4 @@ expect(err).to.not.exist();

var server = new Hapi.Server();
server.pack.register(require('../'), function (err) {
server.connection();
server.register(require('../'), function (err) {

@@ -1401,102 +1431,17 @@ expect(err).to.not.exist();

server.auth.strategy('default', 'cookie', true, {
password: 'password1',
password: 'password',
ttl: 60 * 1000,
domain: 'example.com',
cookie: 'special',
clearInvalid: true,
validateFunc: function (session, callback) {
var override = Hoek.clone(session);
override.something = 'new';
return callback(null, session.user === 'valid', override);
}
clearInvalid: true
});
server.route({
method: 'GET', path: '/login/{user}',
config: {
auth: { mode: 'try' },
handler: function (request, reply) {
server.route({ method: 'GET', path: '/', handler: function (request, reply) { return reply(); } });
request.auth.session.set({ user: request.params.user });
return reply(request.params.user);
}
}
});
server.inject({ url: '/', headers: { cookie: 'sid=123456' } }, function (res) {
server.route({
method: 'GET', path: '/resource', handler: function (request, reply) {
expect(request.auth.credentials.something).to.equal('new');
return reply('resource');
}
expect(res.statusCode).to.equal(401);
expect(res.headers['set-cookie'][0]).to.equal('sid=; Max-Age=0; Expires=Thu, 01 Jan 1970 00:00:00 GMT; Secure; HttpOnly; Path=/');
done();
});
server.inject('/login/valid', function (res) {
expect(res.result).to.equal('valid');
var header = res.headers['set-cookie'];
expect(header.length).to.equal(1);
expect(header[0]).to.contain('Max-Age=60');
var cookie = header[0].match(/(?:[^\x00-\x20\(\)<>@\,;\:\\"\/\[\]\?\=\{\}\x7F]+)\s*=\s*(?:([^\x00-\x20\"\,\;\\\x7F]*))/);
// kill the server, and create a new one, then use the saved cookie
// and see if it gets unset
server.stop(function(){
var server2 = new Hapi.Server();
server2.pack.register(require('../'), function (err) {
server2.auth.strategy('default', 'cookie', true, {
password: 'password2',
ttl: 60 * 1000,
domain: 'example.com',
cookie: 'special',
clearInvalid: true,
validateFunc: function (session, callback) {
var override = Hoek.clone(session);
override.something = 'new';
return callback(null, session.user === 'valid', override);
}
});
server2.route({
method: 'GET', path: '/login/{user}',
config: {
auth: { mode: 'try' },
handler: function (request, reply) {
request.auth.session.set({ user: request.params.user });
return reply(request.params.user);
}
}
});
server2.route({
method: 'GET', path: '/resource', handler: function (request, reply) {
expect(request.auth.credentials.something).to.equal('new');
return reply('resource');
}
});
server2.inject({ method: 'GET', url: '/resource', headers: { cookie: 'special=' + cookie[1] } }, function(res) {
expect(JSON.stringify(res.result)).to.equal('{"statusCode":400,"error":"Bad Request","message":"Bad cookie value: special"}');
var header = res.headers['set-cookie'];
expect(header.length).to.equal(1);
expect(header[0]).to.contain('Max-Age=0');
expect(header[0]).to.contain('Expires=');
expect(header[0]).to.contain('special=;');
done();
});
});
});
});
});
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc