CJVT updates August and September 2026
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
(The MIT License)
|
||||
|
||||
Copyright (c) 2013 Jared Hanson
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
@@ -0,0 +1,28 @@
|
||||
# passport-remember-me-extended (vendored)
|
||||
|
||||
This directory contains a vendored copy of the `passport-remember-me-extended`
|
||||
Passport strategy by Derek Lakin. It provides a "remember me" cookie
|
||||
authentication strategy with support for signed cookies, which the original
|
||||
`passport-remember-me` package does not provide.
|
||||
|
||||
## Why vendored?
|
||||
|
||||
The package was originally published to npm as `passport-remember-me-extended`
|
||||
version 0.0.3 by dereklakin. That version was later unpublished from npm, and
|
||||
the package name was subsequently claimed by an unrelated author.
|
||||
Rather than depending on the npm registry or a personal
|
||||
GitHub fork that could also disappear, the source is vendored directly into
|
||||
this repository.
|
||||
|
||||
## Source
|
||||
|
||||
Copied from commit
|
||||
[`7493da87`](https://github.com/dereklakin/passport-remember-me/tree/7493da87e167060b6c846658d6fb6009331677d1).
|
||||
Only `lib/strategy.js`, `lib/utils.js`, `lib/index.js` and
|
||||
`LICENSE` were copied. The `require('pkginfo')(module, 'version')` call was
|
||||
removed from `index.js` to avoid pulling in the `pkginfo` dependency, since
|
||||
we never read the exposed version string.
|
||||
|
||||
## License
|
||||
|
||||
MIT. See `LICENSE`.
|
||||
@@ -0,0 +1,10 @@
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
var Strategy = require('./strategy');
|
||||
|
||||
|
||||
/**
|
||||
* Expose constructors.
|
||||
*/
|
||||
exports.Strategy = Strategy;
|
||||
@@ -0,0 +1,114 @@
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
var passport = require('passport')
|
||||
, util = require('util')
|
||||
, utils = require('./utils');
|
||||
|
||||
|
||||
/**
|
||||
* `Strategy` constructor.
|
||||
*
|
||||
* @param {Object} options
|
||||
* @api public
|
||||
*/
|
||||
function Strategy(options, verify, issue) {
|
||||
if (typeof options == 'function') {
|
||||
issue = verify;
|
||||
verify = options;
|
||||
options = {};
|
||||
}
|
||||
if (!verify) throw new Error('remember me cookie authentication strategy requires a verify function');
|
||||
if (!issue) throw new Error('remember me cookie authentication strategy requires an issue function');
|
||||
|
||||
var opts = { path: '/', httpOnly: true, maxAge: 604800000 }; // maxAge: 7 days
|
||||
this._key = options.key || 'remember_me';
|
||||
this._opts = utils.merge(opts, options.cookie);
|
||||
|
||||
passport.Strategy.call(this);
|
||||
this.name = 'remember-me';
|
||||
this._verify = verify;
|
||||
this._issue = issue;
|
||||
this._passReqToCallback = !!options.passReqToCallback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inherit from `passport.Strategy`.
|
||||
*/
|
||||
util.inherits(Strategy, passport.Strategy);
|
||||
|
||||
/**
|
||||
* Authenticate request based on remember me cookie.
|
||||
*
|
||||
* @param {Object} req
|
||||
* @api protected
|
||||
*/
|
||||
Strategy.prototype.authenticate = function(req, options) {
|
||||
// The rememeber me cookie is only consumed if the request is not
|
||||
// authenticated. This is in preference to the session, which is typically
|
||||
// established at the same time the remember me cookie is issued.
|
||||
if (req.isAuthenticated()) { return this.pass(); }
|
||||
|
||||
var token = (this._opts !== undefined && this._opts.signed === true ? req.signedCookies[this._key] : req.cookies[this._key]);
|
||||
|
||||
// Since the remember me cookie is primarily a convenience, the lack of one is
|
||||
// not a failure. In this case, a response should be rendered indicating a
|
||||
// logged out state, rather than denying the request.
|
||||
if (!token) { return this.pass(); }
|
||||
|
||||
var self = this;
|
||||
|
||||
function verified(err, user, info) {
|
||||
if (err) { return self.error(err); }
|
||||
|
||||
// Express exposes the response to the request. We need the response to set
|
||||
// a cookie, so we'll grab it this way. This breaks the encapsulation of
|
||||
// Passport's Strategy API, but is acceptable for this strategy.
|
||||
var res = req.res;
|
||||
|
||||
if (!user) {
|
||||
// The remember me cookie was not valid. However, because this
|
||||
// authentication method is primarily a convenience, we don't want to
|
||||
// deny the request. Instead we'll clear the invalid cookie and proceed
|
||||
// to respond in a manner which indicates a logged out state.
|
||||
//
|
||||
// Note that a failure at this point may indicate a possible theft of the
|
||||
// cookie. If handling this situation is a requirement, it is up to the
|
||||
// application to encode the value in such a way that this can be detected.
|
||||
// For a discussion on such matters, refer to:
|
||||
// http://fishbowl.pastiche.org/2004/01/19/persistent_login_cookie_best_practice/
|
||||
// http://jaspan.com/improved_persistent_login_cookie_best_practice
|
||||
// http://web.archive.org/web/20130214051957/http://jaspan.com/improved_persistent_login_cookie_best_practice
|
||||
// http://stackoverflow.com/questions/549/the-definitive-guide-to-forms-based-website-authentication
|
||||
|
||||
res.clearCookie(self._key);
|
||||
return self.pass();
|
||||
}
|
||||
|
||||
// The remember me cookie was valid and consumed. For security reasons,
|
||||
// the just-used token should have been invalidated by the application.
|
||||
// A new token will be issued and set as the value of the remember me
|
||||
// cookie.
|
||||
function issued(err, val) {
|
||||
if (err) { return self.error(err); }
|
||||
res.cookie(self._key, val, self._opts);
|
||||
return self.success(user, info);
|
||||
}
|
||||
|
||||
if (self._passReqToCallback)
|
||||
self._issue(req, user, issued);
|
||||
else
|
||||
self._issue(user, issued);
|
||||
}
|
||||
|
||||
if (self._passReqToCallback)
|
||||
self._verify(req, token, verified);
|
||||
else
|
||||
self._verify(token, verified);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Expose `Strategy`.
|
||||
*/
|
||||
module.exports = Strategy;
|
||||
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* Merge object b with object a.
|
||||
*
|
||||
* var a = { foo: 'bar' }
|
||||
* , b = { bar: 'baz' };
|
||||
*
|
||||
* utils.merge(a, b);
|
||||
* // => { foo: 'bar', bar: 'baz' }
|
||||
*
|
||||
* @param {Object} a
|
||||
* @param {Object} b
|
||||
* @return {Object}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
exports.merge = function(a, b){
|
||||
if (a && b) {
|
||||
for (var key in b) {
|
||||
a[key] = b[key];
|
||||
}
|
||||
}
|
||||
return a;
|
||||
};
|
||||
Reference in New Issue
Block a user