Added node-modules

This commit is contained in:
Dobie Wollert
2014-09-14 07:04:16 -04:00
parent 663941bf57
commit 6a92348cf5
4870 changed files with 670395 additions and 0 deletions

5
node_modules/passport/.travis.yml generated vendored Normal file
View File

@ -0,0 +1,5 @@
language: "node_js"
node_js:
- 0.4
- 0.6
- 0.8

20
node_modules/passport/LICENSE generated vendored Normal file
View File

@ -0,0 +1,20 @@
(The MIT License)
Copyright (c) 2011-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.

138
node_modules/passport/README.md generated vendored Normal file
View File

@ -0,0 +1,138 @@
# Passport
Passport is [Express](http://expressjs.com/)-compatible authentication
middleware for [Node.js](http://nodejs.org/).
Passport's sole purpose is to authenticate requests, which it does through an
extensible set of plugins known as _strategies_. Passport does not mount
routes or assume any particular database schema, which maximizes flexiblity and
allows application-level decisions to be made by the developer. The API is
simple: you provide Passport a request to authenticate, and Passport provides
hooks for controlling what occurs when authentication succeeds or fails.
## Install
$ npm install passport
## Usage
#### Strategies
Passport uses the concept of strategies to authenticate requests. Strategies
can range from verifying username and password credentials, delegated
authentication using [OAuth](http://oauth.net/) (for example, via [Facebook](http://www.facebook.com/)
or [Twitter](http://twitter.com/)), or federated authentication using [OpenID](http://openid.net/).
Before authenticating requests, the strategy (or strategies) used by an
application must be configured.
passport.use(new LocalStrategy(
function(username, password, done) {
User.findOne({ username: username, password: password }, function (err, user) {
done(err, user);
});
}
));
#### Sessions
Passport will maintain persistent login sessions. In order for persistent
sessions to work, the authenticated user must be serialized to the session, and
deserialized when subsequent requests are made.
Passport does not impose any restrictions on how your user records are stored.
Instead, you provide functions to Passport which implements the necessary
serialization and deserialization logic. In a typical application, this will be
as simple as serializing the user ID, and finding the user by ID when
deserializing.
passport.serializeUser(function(user, done) {
done(null, user.id);
});
passport.deserializeUser(function(id, done) {
User.findById(id, function (err, user) {
done(err, user);
});
});
#### Middleware
To use Passport in an [Express](http://expressjs.com/) or
[Connect](http://senchalabs.github.com/connect/)-based application, configure it
with the required `passport.initialize()` middleware. If your application uses
persistent login sessions (recommended, but not required), `passport.session()`
middleware must also be used.
app.configure(function() {
app.use(express.static(__dirname + '/../../public'));
app.use(express.cookieParser());
app.use(express.bodyParser());
app.use(express.session({ secret: 'keyboard cat' }));
app.use(passport.initialize());
app.use(passport.session());
app.use(app.router);
});
#### Authenticate Requests
Passport provides an `authenticate()` function, which is used as route
middleware to authenticate requests.
app.post('/login',
passport.authenticate('local', { failureRedirect: '/login' }),
function(req, res) {
res.redirect('/');
});
## Examples
For a complete, working example, refer to the [login example](https://github.com/jaredhanson/passport-local/tree/master/examples/login)
included in [passport-local](https://github.com/jaredhanson/passport-local).
## Strategies
Passport has a comprehensive set of **over 120** authentication strategies
covering social networking, enterprise integration, API services, and more.
The [complete list](https://github.com/jaredhanson/passport/wiki/Strategies) is
available on the [wiki](https://github.com/jaredhanson/passport/wiki).
The following table lists commonly used strategies:
|Strategy | Protocol |Developer |
|---------------------------------------------------------------|--------------------------|------------------------------------------------|
|[Local](https://github.com/jaredhanson/passport-local) | HTML form |[Jared Hanson](https://github.com/jaredhanson) |
|[OpenID](https://github.com/jaredhanson/passport-openid) | OpenID |[Jared Hanson](https://github.com/jaredhanson) |
|[BrowserID](https://github.com/jaredhanson/passport-browserid) | BrowserID |[Jared Hanson](https://github.com/jaredhanson) |
|[Facebook](https://github.com/jaredhanson/passport-facebook) | OAuth 2.0 |[Jared Hanson](https://github.com/jaredhanson) |
|[Google](https://github.com/jaredhanson/passport-google) | OpenID |[Jared Hanson](https://github.com/jaredhanson) |
|[Google](https://github.com/jaredhanson/passport-google-oauth) | OAuth / OAuth 2.0 |[Jared Hanson](https://github.com/jaredhanson) |
|[Twitter](https://github.com/jaredhanson/passport-twitter) | OAuth |[Jared Hanson](https://github.com/jaredhanson) |
## Related Modules
- [Locomotive](https://github.com/jaredhanson/locomotive) — Powerful MVC web framework
- [OAuthorize](https://github.com/jaredhanson/oauthorize) — OAuth service provider toolkit
- [OAuth2orize](https://github.com/jaredhanson/oauth2orize) — OAuth 2.0 authorization server toolkit
- [connect-ensure-login](https://github.com/jaredhanson/connect-ensure-login) — middleware to ensure login sessions
The [modules](https://github.com/jaredhanson/passport/wiki/Modules) page on the
[wiki](https://github.com/jaredhanson/passport/wiki) lists other useful modules
that build upon or integrate with Passport.
## Tests
$ npm install --dev
$ make test
[![Build Status](https://secure.travis-ci.org/jaredhanson/passport.png)](http://travis-ci.org/jaredhanson/passport)
## Credits
- [Jared Hanson](http://github.com/jaredhanson)
## License
[The MIT License](http://opensource.org/licenses/MIT)
Copyright (c) 2011-2013 Jared Hanson <[http://jaredhanson.net/](http://jaredhanson.net/)>

View File

@ -0,0 +1,93 @@
/**
* Export actions prototype for strategies operating within an HTTP context.
*/
var actions = module.exports = {};
/**
* Authenticate `user`, with optional `info`.
*
* Strategies should call this function to successfully authenticate a user.
* `user` should be an object supplied by the application after it has been
* given an opportunity to verify credentials. `info` is an optional argument
* containing additional user information. This is useful for third-party
* authentication strategies to pass profile details.
*
* @param {Object} user
* @param {Object} info
* @api public
*/
actions.success = function(user, info) {
this.delegate.success.apply(this, arguments);
}
/**
* Fail authentication, with optional `challenge` and `status`, defaulting to
* 401.
*
* Strategies should call this function to fail an authentication attempt.
*
* @param {String} challenge
* @param {Number} status
* @api public
*/
actions.fail = function(challenge, status) {
this.delegate.fail.apply(this, arguments);
}
/**
* Redirect to `url` with optional `status`, defaulting to 302.
*
* Strategies should call this function to redirect the user (via their user
* agent) to a third-party website for authentication.
*
* @param {String} url
* @param {Number} status
* @api public
*/
actions.redirect = function(url, status) {
var res = this.res;
if (typeof res.redirect == 'function') {
// If possible use redirect method on the response
// Assume Express API, optional status param comes first
if (status) {
res.redirect(status, url);
} else {
res.redirect(url);
}
} else {
// Otherwise fall back to native methods
res.statusCode = status || 302;
res.setHeader('Location', url);
res.setHeader('Content-Length', '0');
res.end();
}
}
/**
* Pass without making a success or fail decision.
*
* Under most circumstances, Strategies should not need to call this function.
* It exists primarily to allow previous authentication state to be restored,
* for example from an HTTP session.
*
* @api public
*/
actions.pass = function() {
this.next();
}
/**
* Internal error while performing authentication.
*
* Strategies should call this function when an internal error occurs during the
* process of performing authentication; for example, if the user directory is
* not available.
*
* @param {Error} err
* @api public
*/
actions.error = function(err) {
this.next(err);
}

View File

@ -0,0 +1,17 @@
/**
* `Context` constructor.
*
* @api private
*/
function Context(delegate, req, res, next) {
this.delegate = delegate;
this.req = req;
this.res = res;
this.next = next;
}
/**
* Expose `Context`.
*/
module.exports = Context;

91
node_modules/passport/lib/passport/http/request.js generated vendored Normal file
View File

@ -0,0 +1,91 @@
/**
* Module dependencies.
*/
var http = require('http')
, req = http.IncomingMessage.prototype;
/**
* Intiate a login session for `user`.
*
* Options:
* - `session` Save login state in session, defaults to _true_
*
* Examples:
*
* req.logIn(user, { session: false });
*
* req.logIn(user, function(err) {
* if (err) { throw err; }
* // session saved
* });
*
* @param {User} user
* @param {Object} options
* @param {Function} done
* @api public
*/
req.login =
req.logIn = function(user, options, done) {
if (!this._passport) throw new Error('passport.initialize() middleware not in use');
if (!done && typeof options === 'function') {
done = options;
options = {};
}
options = options || {};
var property = this._passport.instance._userProperty || 'user';
var session = (options.session === undefined) ? true : options.session;
this[property] = user;
if (session) {
var self = this;
this._passport.instance.serializeUser(user, function(err, obj) {
if (err) { self[property] = null; return done(err); }
self._passport.session.user = obj;
done();
});
} else {
done && done();
}
}
/**
* Terminate an existing login session.
*
* @api public
*/
req.logout =
req.logOut = function() {
if (!this._passport) throw new Error('passport.initialize() middleware not in use');
var property = this._passport.instance._userProperty || 'user';
this[property] = null;
delete this._passport.session.user;
};
/**
* Test if request is authenticated.
*
* @return {Boolean}
* @api public
*/
req.isAuthenticated = function() {
var property = 'user';
if (this._passport && this._passport.instance._userProperty) {
property = this._passport.instance._userProperty;
}
return (this[property]) ? true : false;
};
/**
* Test if request is unauthenticated.
*
* @return {Boolean}
* @api public
*/
req.isUnauthenticated = function() {
return !this.isAuthenticated();
};

453
node_modules/passport/lib/passport/index.js generated vendored Normal file
View File

@ -0,0 +1,453 @@
/**
* Module dependencies.
*/
var fs = require('fs')
, path = require('path')
, util = require('util')
, Strategy = require('./strategy')
, SessionStrategy = require('./strategies/session')
, initialize = require('./middleware/initialize')
, authenticate = require('./middleware/authenticate');
/**
* `Passport` constructor.
*
* @api public
*/
function Passport() {
this._key = 'passport';
this._strategies = {};
this._serializers = [];
this._deserializers = [];
this._infoTransformers = [];
this._framework = null;
this._userProperty = 'user';
this.use(new SessionStrategy());
};
/**
* Utilize the given `strategy` with optional `name`, overridding the strategy's
* default name.
*
* Examples:
*
* passport.use(new TwitterStrategy(...));
*
* passport.use('api', new http.BasicStrategy(...));
*
* @param {String|Strategy} name
* @param {Strategy} strategy
* @return {Passport} for chaining
* @api public
*/
Passport.prototype.use = function(name, strategy) {
if (!strategy) {
strategy = name;
name = strategy.name;
}
if (!name) throw new Error('authentication strategies must have a name');
this._strategies[name] = strategy;
return this;
};
/**
* Un-utilize the `strategy` with given `name`.
*
* In typical applications, the necessary authentication strategies are static,
* configured once and always available. As such, there is often no need to
* invoke this function.
*
* However, in certain situations, applications may need dynamically configure
* and de-configure authentication strategies. The `use()`/`unuse()`
* combination satisfies these scenarios.
*
* Examples:
*
* passport.unuse('legacy-api');
*
* @param {String} name
* @return {Passport} for chaining
* @api public
*/
Passport.prototype.unuse = function(name) {
delete this._strategies[name];
return this;
}
/**
* Setup Passport to be used under framework.
*
* By default, Passport exposes middleware that operate using Connect-style
* middleware using a `fn(req, res, next)` signature. Other popular frameworks
* have different expectations, and this function allows Passport to be adapted
* to operate within such environments.
*
* If you are using a Connect-compatible framework, including Express, there is
* no need to invoke this function.
*
* Examples:
*
* passport.framework(require('hapi-passport')());
*
* @param {Object} name
* @return {Passport} for chaining
* @api public
*/
Passport.prototype.framework = function(fw) {
this._framework = fw;
return this;
}
/**
* Passport's primary initialization middleware.
*
* This middleware must be in use by the Connect/Express application for
* Passport to operate.
*
* Options:
* - `userProperty` Property to set on `req` upon login, defaults to _user_
*
* Examples:
*
* app.configure(function() {
* app.use(passport.initialize());
* });
*
* app.configure(function() {
* app.use(passport.initialize({ userProperty: 'currentUser' }));
* });
*
* @param {Object} options
* @return {Function} middleware
* @api public
*/
Passport.prototype.initialize = function(options) {
options = options || {};
this._userProperty = options.userProperty || 'user';
if (this._framework && this._framework.initialize) {
return this._framework.initialize().bind(this);
}
return initialize().bind(this);
}
/**
* Middleware that will restore login state from a session.
*
* Web applications typically use sessions to maintain login state between
* requests. For example, a user will authenticate by entering credentials into
* a form which is submitted to the server. If the credentials are valid, a
* login session is established by setting a cookie containing a session
* identifier in the user's web browser. The web browser will send this cookie
* in subsequent requests to the server, allowing a session to be maintained.
*
* If sessions are being utilized, and a login session has been established,
* this middleware will populate `req.user` with the current user.
*
* Note that sessions are not strictly required for Passport to operate.
* However, as a general rule, most web applications will make use of sessions.
* An exception to this rule would be an API server, which expects each HTTP
* request to provide credentials in an Authorization header.
*
* Examples:
*
* app.configure(function() {
* app.use(connect.cookieParser());
* app.use(connect.session({ secret: 'keyboard cat' }));
* app.use(passport.initialize());
* app.use(passport.session());
* });
*
* Options:
* - `pauseStream` Pause the request stream before deserializing the user
* object from the session. Defaults to _false_. Should
* be set to true in cases where middleware consuming the
* request body is configured after passport and the
* deserializeUser method is asynchronous.
*
* @param {Object} options
* @return {Function} middleware
* @api public
*/
Passport.prototype.session = function(options) {
return this.authenticate('session', options);
}
/**
* Middleware that will authenticate a request using the given `strategy` name,
* with optional `options` and `callback`.
*
* Examples:
*
* passport.authenticate('local', { successRedirect: '/', failureRedirect: '/login' })(req, res);
*
* passport.authenticate('local', function(err, user) {
* if (!user) { return res.redirect('/login'); }
* res.end('Authenticated!');
* })(req, res);
*
* passport.authenticate('basic', { session: false })(req, res);
*
* app.get('/auth/twitter', passport.authenticate('twitter'), function(req, res) {
* // request will be redirected to Twitter
* });
* app.get('/auth/twitter/callback', passport.authenticate('twitter'), function(req, res) {
* res.json(req.user);
* });
*
* @param {String} strategy
* @param {Object} options
* @param {Function} callback
* @return {Function} middleware
* @api public
*/
Passport.prototype.authenticate = function(strategy, options, callback) {
if (this._framework && this._framework.authenticate) {
return this._framework.authenticate(strategy, options, callback).bind(this);
}
return authenticate(strategy, options, callback).bind(this);
}
/**
* Middleware that will authorize a third-party account using the given
* `strategy` name, with optional `options`.
*
* If authorization is successful, the result provided by the strategy's verify
* callback will be assigned to `req.account`. The existing login session and
* `req.user` will be unaffected.
*
* This function is particularly useful when connecting third-party accounts
* to the local account of a user that is currently authenticated.
*
* Examples:
*
* passport.authorize('twitter-authz', { failureRedirect: '/account' });
*
* @param {String} strategy
* @param {Object} options
* @return {Function} middleware
* @api public
*/
Passport.prototype.authorize = function(strategy, options, callback) {
options = options || {};
options.assignProperty = 'account';
return authenticate(strategy, options, callback).bind(this);
}
/**
* Registers a function used to serialize user objects into the session.
*
* Examples:
*
* passport.serializeUser(function(user, done) {
* done(null, user.id);
* });
*
* @api public
*/
Passport.prototype.serializeUser = function(fn, done) {
if (typeof fn === 'function') {
return this._serializers.push(fn);
}
// private implementation that traverses the chain of serializers, attempting
// to serialize a user
var user = fn;
var stack = this._serializers;
(function pass(i, err, obj) {
// serializers use 'pass' as an error to skip processing
if ('pass' === err) {
err = undefined;
}
// an error or serialized object was obtained, done
if (err || obj || obj === 0) { return done(err, obj); }
var layer = stack[i];
if (!layer) {
return done(new Error('failed to serialize user into session'));
}
try {
layer(user, function(e, o) { pass(i + 1, e, o); } )
} catch(e) {
return done(e);
}
})(0);
}
/**
* Registers a function used to deserialize user objects out of the session.
*
* Examples:
*
* passport.deserializeUser(function(id, done) {
* User.findById(id, function (err, user) {
* done(err, user);
* });
* });
*
* @api public
*/
Passport.prototype.deserializeUser = function(fn, done) {
if (typeof fn === 'function') {
return this._deserializers.push(fn);
}
// private implementation that traverses the chain of deserializers,
// attempting to deserialize a user
var obj = fn;
var stack = this._deserializers;
(function pass(i, err, user) {
// deserializers use 'pass' as an error to skip processing
if ('pass' === err) {
err = undefined;
}
// an error or deserialized user was obtained, done
if (err || user) { return done(err, user); }
// a valid user existed when establishing the session, but that user has
// since been removed
if (user === null || user === false) { return done(null, false); }
var layer = stack[i];
if (!layer) {
return done(new Error('failed to deserialize user out of session'));
}
try {
layer(obj, function(e, u) { pass(i + 1, e, u); } )
} catch(e) {
return done(e);
}
})(0);
}
/**
* Registers a function used to transform auth info.
*
* In some circumstances authorization details are contained in authentication
* credentials or loaded as part of verification.
*
* For example, when using bearer tokens for API authentication, the tokens may
* encode (either directly or indirectly in a database), details such as scope
* of access or the client to which the token was issued.
*
* Such authorization details should be enforced separately from authentication.
* Because Passport deals only with the latter, this is the responsiblity of
* middleware or routes further along the chain. However, it is not optimal to
* decode the same data or execute the same database query later. To avoid
* this, Passport accepts optional `info` along with the authenticated `user`
* in a strategy's `success()` action. This info is set at `req.authInfo`,
* where said later middlware or routes can access it.
*
* Optionally, applications can register transforms to proccess this info,
* which take effect prior to `req.authInfo` being set. This is useful, for
* example, when the info contains a client ID. The transform can load the
* client from the database and include the instance in the transformed info,
* allowing the full set of client properties to be convieniently accessed.
*
* If no transforms are registered, `info` supplied by the strategy will be left
* unmodified.
*
* Examples:
*
* passport.transformAuthInfo(function(info, done) {
* Client.findById(info.clientID, function (err, client) {
* info.client = client;
* done(err, info);
* });
* });
*
* @api public
*/
Passport.prototype.transformAuthInfo = function(fn, done) {
if (typeof fn === 'function') {
return this._infoTransformers.push(fn);
}
// private implementation that traverses the chain of transformers,
// attempting to transform auth info
var info = fn;
var stack = this._infoTransformers;
(function pass(i, err, tinfo) {
// transformers use 'pass' as an error to skip processing
if ('pass' === err) {
err = undefined;
}
// an error or transformed info was obtained, done
if (err || tinfo) { return done(err, tinfo); }
var layer = stack[i];
if (!layer) {
// if no transformers are registered (or they all pass), the default
// behavior is to use the un-transformed info as-is
return done(null, info);
}
try {
var arity = layer.length;
if (arity == 1) {
// sync
var t = layer(info);
pass(i + 1, null, t);
} else {
// async
layer(info, function(e, t) { pass(i + 1, e, t); } )
}
} catch(e) {
return done(e);
}
})(0);
}
/**
* Return strategy with given `name`.
*
* @param {String} name
* @return {Strategy}
* @api private
*/
Passport.prototype._strategy = function(name) {
return this._strategies[name];
}
/**
* Export default singleton.
*
* @api public
*/
exports = module.exports = new Passport();
/**
* Framework version.
*/
require('pkginfo')(module, 'version');
/**
* Expose constructors.
*/
exports.Passport = Passport;
exports.Strategy = Strategy;
/**
* Expose strategies.
*/
exports.strategies = {};
exports.strategies.SessionStrategy = SessionStrategy;
/**
* HTTP extensions.
*/
require('./http/request');

View File

@ -0,0 +1,253 @@
/**
* Module dependencies.
*/
var util = require('util')
, actions = require('../context/http/actions')
, Context = require('../context/http/context')
/**
* Authenticates requests.
*
* Applies the `name`ed strategy (or strategies) to the incoming request, in
* order to authenticate the request. If authentication is successful, the user
* will be logged in and populated at `req.user` and a session will be
* established by default. If authentication fails, an unauthorized response
* will be sent.
*
* Options:
* - `session` Save login state in session, defaults to _true_
* - `successRedirect` After successful login, redirect to given URL
* - `failureRedirect` After failed login, redirect to given URL
* - `assignProperty` Assign the object provided by the verify callback to given property
*
* An optional `callback` can be supplied to allow the application to overrride
* the default manner in which authentication attempts are handled. The
* callback has the following signature, where `user` will be set to the
* authenticated user on a successful authentication attempt, or `false`
* otherwise. An optional `info` argument will be passed, containing additional
* details provided by the strategy's verify callback.
*
* app.get('/protected', function(req, res, next) {
* passport.authenticate('local', function(err, user, info) {
* if (err) { return next(err) }
* if (!user) { return res.redirect('/signin') }
* res.redirect('/account');
* })(req, res, next);
* });
*
* Note that if a callback is supplied, it becomes the application's
* responsibility to log-in the user, establish a session, and otherwise perform
* the desired operations.
*
* Examples:
*
* passport.authenticate('local', { successRedirect: '/', failureRedirect: '/login' });
*
* passport.authenticate('basic', { session: false });
*
* passport.authenticate('twitter');
*
* @param {String} name
* @param {Object} options
* @param {Function} callback
* @return {Function}
* @api public
*/
module.exports = function authenticate(name, options, callback) {
if (!callback && typeof options === 'function') {
callback = options;
options = {};
}
options = options || {};
// Cast `name` to an array, allowing authentication to pass through a chain of
// strategies. The first strategy to succeed, redirect, or error will halt
// the chain. Authentication failures will proceed through each strategy in
// series, ultimately failing if all strategies fail.
//
// This is typically used on API endpoints to allow clients to authenticate
// using their preferred choice of Basic, Digest, token-based schemes, etc.
// It is not feasible to construct a chain of multiple strategies that involve
// redirection (for example both Facebook and Twitter), since the first one to
// redirect will halt the chain.
if (!Array.isArray(name)) {
name = [ name ];
}
return function authenticate(req, res, next) {
var passport = this;
// accumulator for failures from each strategy in the chain
var failures = [];
function allFailed() {
if (callback) {
if (failures.length == 1) {
return callback(null, false, failures[0].challenge, failures[0].status);
} else {
var challenges = failures.map(function(f) { return f.challenge; });
var statuses = failures.map(function(f) { return f.status; })
return callback(null, false, challenges, statuses);
}
}
// Strategies are ordered by priority. For the purpose of flashing a
// message, the first failure will be displayed.
var failure = failures[0] || {}
, challenge = failure.challenge || {};
if (options.failureFlash) {
var flash = options.failureFlash;
if (typeof flash == 'string') {
flash = { type: 'error', message: flash };
}
flash.type = flash.type || 'error';
var type = flash.type || challenge.type || 'error';
var msg = flash.message || challenge.message || challenge;
if (typeof msg == 'string') {
req.flash(type, msg);
}
}
if (options.failureMessage) {
var msg = options.failureMessage;
if (typeof msg == 'boolean') {
msg = challenge.message || challenge;
}
if (typeof msg == 'string') {
req.session.messages = req.session.messages || [];
req.session.messages.push(msg);
}
}
if (options.failureRedirect) {
return res.redirect(options.failureRedirect);
}
// When failure handling is not delegated to the application, the default
// is to respond with 401 Unauthorized. Note that the WWW-Authenticate
// header will be set according to the strategies in use (see
// actions#fail). If multiple strategies failed, each of their challenges
// will be included in the response.
var rchallenge = []
, rstatus;
for (var j = 0, len = failures.length; j < len; j++) {
var failure = failures[j]
, challenge = failure.challenge || {}
, status = failure.status;
if (typeof challenge == 'number') {
status = challenge;
challenge = null;
}
rstatus = rstatus || status;
if (typeof challenge == 'string') {
rchallenge.push(challenge)
}
}
res.statusCode = rstatus || 401;
if (rchallenge.length) {
res.setHeader('WWW-Authenticate', rchallenge);
}
res.end('Unauthorized');
}
(function attempt(i) {
var delegate = {};
delegate.success = function(user, info) {
if (callback) {
return callback(null, user, info);
}
info = info || {}
if (options.successFlash) {
var flash = options.successFlash;
if (typeof flash == 'string') {
flash = { type: 'success', message: flash };
}
flash.type = flash.type || 'success';
var type = flash.type || info.type || 'success';
var msg = flash.message || info.message || info;
if (typeof msg == 'string') {
req.flash(type, msg);
}
}
if (options.successMessage) {
var msg = options.successMessage;
if (typeof msg == 'boolean') {
msg = info.message || info;
}
if (typeof msg == 'string') {
req.session.messages = req.session.messages || [];
req.session.messages.push(msg);
}
}
if (options.assignProperty) {
req[options.assignProperty] = user;
return next();
}
req.logIn(user, options, function(err) {
if (err) { return next(err); }
if (options.authInfo || options.authInfo === undefined) {
passport.transformAuthInfo(info, function(err, tinfo) {
if (err) { return next(err); }
req.authInfo = tinfo;
complete();
});
} else {
complete();
}
function complete() {
if (options.successReturnToOrRedirect) {
var url = options.successReturnToOrRedirect;
if (req.session && req.session.returnTo) {
url = req.session.returnTo;
delete req.session.returnTo;
}
return res.redirect(url);
}
if (options.successRedirect) {
return res.redirect(options.successRedirect);
}
next();
}
});
}
delegate.fail = function(challenge, status) {
// push this failure into the accumulator and attempt authentication
// using the next strategy
failures.push({ challenge: challenge, status: status });
attempt(i + 1);
}
var layer = name[i];
// If no more strategies exist in the chain, authentication has failed.
if (!layer) { return allFailed(); }
// Get the strategy, which will be used as prototype from which to create
// a new instance. Action functions will then be bound to the strategy
// within the context of the HTTP request/response pair.
var prototype = passport._strategy(layer);
if (!prototype) { return next(new Error('no strategy registered under name: ' + layer)); }
var strategy = Object.create(prototype);
var context = new Context(delegate, req, res, next);
augment(strategy, actions, context);
strategy.authenticate(req, options);
})(0); // attempt
}
}
function augment(strategy, actions, ctx) {
for (var method in actions) {
strategy[method] = actions[method].bind(ctx);
}
}

View File

@ -0,0 +1,71 @@
/**
* Module dependencies.
*/
var util = require('util');
/**
* Passport initialization.
*
* Intializes Passport for incoming requests, allowing authentication strategies
* to be applied.
*
* If sessions are being utilized, applications must set up Passport with
* functions to serialize a user into and out of a session. For example, a
* common pattern is to serialize just the user ID into the session (due to the
* fact that it is desirable to store the minimum amount of data in a session).
* When a subsequent request arrives for the session, the full User object can
* be loaded from the database by ID.
*
* Note that additional middleware is required to persist login state, so we
* must use the `connect.session()` middleware _before_ `passport.initialize()`.
*
* This middleware must be in use by the Connect/Express application for
* Passport to operate.
*
* Examples:
*
* app.configure(function() {
* app.use(connect.cookieParser());
* app.use(connect.session({ secret: 'keyboard cat' }));
* app.use(passport.initialize());
* app.use(passport.session());
* });
*
* passport.serializeUser(function(user, done) {
* done(null, user.id);
* });
*
* passport.deserializeUser(function(id, done) {
* User.findById(id, function (err, user) {
* done(err, user);
* });
* });
*
* @return {Function}
* @api public
*/
module.exports = function initialize() {
return function initialize(req, res, next) {
var passport = this;
req._passport = {};
req._passport.instance = passport;
//console.log('!! session: ' + util.inspect(req.session));
if (req.session && req.session[passport._key]) {
// load data from existing session
req._passport.session = req.session[passport._key];
} else if (req.session) {
// initialize new session
req.session[passport._key] = {};
req._passport.session = req.session[passport._key];
} else {
// no session is available
req._passport.session = {};
}
next();
}
}

View File

@ -0,0 +1,75 @@
/**
* Module dependencies.
*/
var pause = require('pause')
, util = require('util')
, Strategy = require('../strategy');
/**
* `SessionStrategy` constructor.
*
* @api protected
*/
function SessionStrategy() {
Strategy.call(this);
this.name = 'session';
}
/**
* Inherit from `Strategy`.
*/
util.inherits(SessionStrategy, Strategy);
/**
* Authenticate request based on the current session state.
*
* The session authentication strategy uses the session to restore any login
* state across requests. If a login session has been established, `req.user`
* will be populated with the current user.
*
* This strategy is registered automatically by Passport.
*
* @param {Object} req
* @param {Object} options
* @api protected
*/
SessionStrategy.prototype.authenticate = function(req, options) {
if (!req._passport) { return this.error(new Error('passport.initialize() middleware not in use')); }
options = options || {};
var self = this
, su = req._passport.session.user;
if (su || su === 0) {
// NOTE: Stream pausing is desirable in the case where later middleware is
// listening for events emitted from request. For discussion on the
// matter, refer to: https://github.com/jaredhanson/passport/pull/106
var paused = options.pauseStream ? pause(req) : null;
req._passport.instance.deserializeUser(su, function(err, user) {
if (err) { return self.error(err); }
if (!user) {
delete req._passport.session.user;
self.pass();
if (paused) {
paused.resume();
}
return;
};
var property = req._passport.instance._userProperty || 'user';
req[property] = user;
self.pass();
if (paused) {
paused.resume();
}
});
} else {
self.pass();
}
}
/**
* Expose `SessionStrategy`.
*/
module.exports = SessionStrategy;

33
node_modules/passport/lib/passport/strategy.js generated vendored Normal file
View File

@ -0,0 +1,33 @@
/**
* Module dependencies.
*/
var util = require('util');
/**
* `Strategy` constructor.
*
* @api public
*/
function Strategy() {
}
/**
* Authenticate request.
*
* This function must be overridden by subclasses. In abstract form, it always
* throws an exception.
*
* @param {Object} req
* @param {Object} options
* @api protected
*/
Strategy.prototype.authenticate = function(req, options) {
throw new Error('Strategy#authenticate must be overridden by subclass');
}
/**
* Expose `Strategy`.
*/
module.exports = Strategy;

4
node_modules/passport/node_modules/pause/.npmignore generated vendored Normal file
View File

@ -0,0 +1,4 @@
support
test
examples
*.sock

5
node_modules/passport/node_modules/pause/History.md generated vendored Normal file
View File

@ -0,0 +1,5 @@
0.0.1 / 2010-01-03
==================
* Initial release

7
node_modules/passport/node_modules/pause/Makefile generated vendored Normal file
View File

@ -0,0 +1,7 @@
test:
@./node_modules/.bin/mocha \
--require should \
--reporter spec
.PHONY: test

29
node_modules/passport/node_modules/pause/Readme.md generated vendored Normal file
View File

@ -0,0 +1,29 @@
# pause
Pause streams...
## License
(The MIT License)
Copyright (c) 2012 TJ Holowaychuk &lt;tj@vision-media.ca&gt;
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.

29
node_modules/passport/node_modules/pause/index.js generated vendored Normal file
View File

@ -0,0 +1,29 @@
module.exports = function(obj){
var onData
, onEnd
, events = [];
// buffer data
obj.on('data', onData = function(data, encoding){
events.push(['data', data, encoding]);
});
// buffer end
obj.on('end', onEnd = function(data, encoding){
events.push(['end', data, encoding]);
});
return {
end: function(){
obj.removeListener('data', onData);
obj.removeListener('end', onEnd);
},
resume: function(){
this.end();
for (var i = 0, len = events.length; i < len; ++i) {
obj.emit.apply(obj, events[i]);
}
}
};
};

24
node_modules/passport/node_modules/pause/package.json generated vendored Normal file
View File

@ -0,0 +1,24 @@
{
"name": "pause",
"version": "0.0.1",
"description": "Pause streams...",
"keywords": [],
"author": {
"name": "TJ Holowaychuk",
"email": "tj@vision-media.ca"
},
"dependencies": {},
"devDependencies": {
"mocha": "*",
"should": "*"
},
"main": "index",
"readme": "\n# pause\n\n Pause streams...\n\n## License \n\n(The MIT License)\n\nCopyright (c) 2012 TJ Holowaychuk &lt;tj@vision-media.ca&gt;\n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n'Software'), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\nIN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\nCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\nTORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\nSOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
"readmeFilename": "Readme.md",
"_id": "pause@0.0.1",
"dist": {
"shasum": "e105f34d8354a6de38513898cbc178d85cb098e7"
},
"_from": "pause@0.0.1",
"_resolved": "https://registry.npmjs.org/pause/-/pause-0.0.1.tgz"
}

View File

@ -0,0 +1,2 @@
node_modules/
npm-debug.log

85
node_modules/passport/node_modules/pkginfo/README.md generated vendored Normal file
View File

@ -0,0 +1,85 @@
# node-pkginfo
An easy way to expose properties on a module from a package.json
## Installation
### Installing npm (node package manager)
```
curl http://npmjs.org/install.sh | sh
```
### Installing pkginfo
```
[sudo] npm install pkginfo
```
## Motivation
How often when writing node.js modules have you written the following line(s) of code?
* Hard code your version string into your code
``` js
exports.version = '0.1.0';
```
* Programmatically expose the version from the package.json
``` js
exports.version = JSON.parse(fs.readFileSync('/path/to/package.json', 'utf8')).version;
```
In other words, how often have you wanted to expose basic information from your package.json onto your module programmatically? **WELL NOW YOU CAN!**
## Usage
Using `pkginfo` is idiot-proof, just require and invoke it.
``` js
var pkginfo = require('pkginfo')(module);
console.dir(module.exports);
```
By invoking the `pkginfo` module all of the properties in your `package.json` file will be automatically exposed on the callee module (i.e. the parent module of `pkginfo`).
Here's a sample of the output:
```
{ name: 'simple-app',
description: 'A test fixture for pkginfo',
version: '0.1.0',
author: 'Charlie Robbins <charlie.robbins@gmail.com>',
keywords: [ 'test', 'fixture' ],
main: './index.js',
scripts: { test: 'vows test/*-test.js --spec' },
engines: { node: '>= 0.4.0' } }
```
### Expose specific properties
If you don't want to expose **all** properties on from your `package.json` on your module then simple pass those properties to the `pkginfo` function:
``` js
var pkginfo = require('pkginfo')(module, 'version', 'author');
console.dir(module.exports);
```
```
{ version: '0.1.0',
author: 'Charlie Robbins <charlie.robbins@gmail.com>' }
```
If you're looking for further usage see the [examples][0] included in this repository.
## Run Tests
Tests are written in [vows][1] and give complete coverage of all APIs.
```
vows test/*-test.js --spec
```
[0]: https://github.com/indexzero/node-pkginfo/tree/master/examples
[1]: http://vowsjs.org
#### Author: [Charlie Robbins](http://nodejitsu.com)

View File

@ -0,0 +1,194 @@
/*--------------------- Layout and Typography ----------------------------*/
body {
font-family: 'Palatino Linotype', 'Book Antiqua', Palatino, FreeSerif, serif;
font-size: 15px;
line-height: 22px;
color: #252519;
margin: 0; padding: 0;
}
a {
color: #261a3b;
}
a:visited {
color: #261a3b;
}
p {
margin: 0 0 15px 0;
}
h4, h5, h6 {
color: #333;
margin: 6px 0 6px 0;
font-size: 13px;
}
h2, h3 {
margin-bottom: 0;
color: #000;
}
h1 {
margin-top: 40px;
margin-bottom: 15px;
color: #000;
}
#container {
position: relative;
}
#background {
position: fixed;
top: 0; left: 525px; right: 0; bottom: 0;
background: #f5f5ff;
border-left: 1px solid #e5e5ee;
z-index: -1;
}
#jump_to, #jump_page {
background: white;
-webkit-box-shadow: 0 0 25px #777; -moz-box-shadow: 0 0 25px #777;
-webkit-border-bottom-left-radius: 5px; -moz-border-radius-bottomleft: 5px;
font: 10px Arial;
text-transform: uppercase;
cursor: pointer;
text-align: right;
}
#jump_to, #jump_wrapper {
position: fixed;
right: 0; top: 0;
padding: 5px 10px;
}
#jump_wrapper {
padding: 0;
display: none;
}
#jump_to:hover #jump_wrapper {
display: block;
}
#jump_page {
padding: 5px 0 3px;
margin: 0 0 25px 25px;
}
#jump_page .source {
display: block;
padding: 5px 10px;
text-decoration: none;
border-top: 1px solid #eee;
}
#jump_page .source:hover {
background: #f5f5ff;
}
#jump_page .source:first-child {
}
table td {
border: 0;
outline: 0;
}
td.docs, th.docs {
max-width: 450px;
min-width: 450px;
min-height: 5px;
padding: 10px 25px 1px 50px;
overflow-x: hidden;
vertical-align: top;
text-align: left;
}
.docs pre {
margin: 15px 0 15px;
padding-left: 15px;
}
.docs p tt, .docs p code {
background: #f8f8ff;
border: 1px solid #dedede;
font-size: 12px;
padding: 0 0.2em;
}
.pilwrap {
position: relative;
}
.pilcrow {
font: 12px Arial;
text-decoration: none;
color: #454545;
position: absolute;
top: 3px; left: -20px;
padding: 1px 2px;
opacity: 0;
-webkit-transition: opacity 0.2s linear;
}
td.docs:hover .pilcrow {
opacity: 1;
}
td.code, th.code {
padding: 14px 15px 16px 25px;
width: 100%;
vertical-align: top;
background: #f5f5ff;
border-left: 1px solid #e5e5ee;
}
pre, tt, code {
font-size: 12px; line-height: 18px;
font-family: Menlo, Monaco, Consolas, "Lucida Console", monospace;
margin: 0; padding: 0;
}
/*---------------------- Syntax Highlighting -----------------------------*/
td.linenos { background-color: #f0f0f0; padding-right: 10px; }
span.lineno { background-color: #f0f0f0; padding: 0 5px 0 5px; }
body .hll { background-color: #ffffcc }
body .c { color: #408080; font-style: italic } /* Comment */
body .err { border: 1px solid #FF0000 } /* Error */
body .k { color: #954121 } /* Keyword */
body .o { color: #666666 } /* Operator */
body .cm { color: #408080; font-style: italic } /* Comment.Multiline */
body .cp { color: #BC7A00 } /* Comment.Preproc */
body .c1 { color: #408080; font-style: italic } /* Comment.Single */
body .cs { color: #408080; font-style: italic } /* Comment.Special */
body .gd { color: #A00000 } /* Generic.Deleted */
body .ge { font-style: italic } /* Generic.Emph */
body .gr { color: #FF0000 } /* Generic.Error */
body .gh { color: #000080; font-weight: bold } /* Generic.Heading */
body .gi { color: #00A000 } /* Generic.Inserted */
body .go { color: #808080 } /* Generic.Output */
body .gp { color: #000080; font-weight: bold } /* Generic.Prompt */
body .gs { font-weight: bold } /* Generic.Strong */
body .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
body .gt { color: #0040D0 } /* Generic.Traceback */
body .kc { color: #954121 } /* Keyword.Constant */
body .kd { color: #954121; font-weight: bold } /* Keyword.Declaration */
body .kn { color: #954121; font-weight: bold } /* Keyword.Namespace */
body .kp { color: #954121 } /* Keyword.Pseudo */
body .kr { color: #954121; font-weight: bold } /* Keyword.Reserved */
body .kt { color: #B00040 } /* Keyword.Type */
body .m { color: #666666 } /* Literal.Number */
body .s { color: #219161 } /* Literal.String */
body .na { color: #7D9029 } /* Name.Attribute */
body .nb { color: #954121 } /* Name.Builtin */
body .nc { color: #0000FF; font-weight: bold } /* Name.Class */
body .no { color: #880000 } /* Name.Constant */
body .nd { color: #AA22FF } /* Name.Decorator */
body .ni { color: #999999; font-weight: bold } /* Name.Entity */
body .ne { color: #D2413A; font-weight: bold } /* Name.Exception */
body .nf { color: #0000FF } /* Name.Function */
body .nl { color: #A0A000 } /* Name.Label */
body .nn { color: #0000FF; font-weight: bold } /* Name.Namespace */
body .nt { color: #954121; font-weight: bold } /* Name.Tag */
body .nv { color: #19469D } /* Name.Variable */
body .ow { color: #AA22FF; font-weight: bold } /* Operator.Word */
body .w { color: #bbbbbb } /* Text.Whitespace */
body .mf { color: #666666 } /* Literal.Number.Float */
body .mh { color: #666666 } /* Literal.Number.Hex */
body .mi { color: #666666 } /* Literal.Number.Integer */
body .mo { color: #666666 } /* Literal.Number.Oct */
body .sb { color: #219161 } /* Literal.String.Backtick */
body .sc { color: #219161 } /* Literal.String.Char */
body .sd { color: #219161; font-style: italic } /* Literal.String.Doc */
body .s2 { color: #219161 } /* Literal.String.Double */
body .se { color: #BB6622; font-weight: bold } /* Literal.String.Escape */
body .sh { color: #219161 } /* Literal.String.Heredoc */
body .si { color: #BB6688; font-weight: bold } /* Literal.String.Interpol */
body .sx { color: #954121 } /* Literal.String.Other */
body .sr { color: #BB6688 } /* Literal.String.Regex */
body .s1 { color: #219161 } /* Literal.String.Single */
body .ss { color: #19469D } /* Literal.String.Symbol */
body .bp { color: #954121 } /* Name.Builtin.Pseudo */
body .vc { color: #19469D } /* Name.Variable.Class */
body .vg { color: #19469D } /* Name.Variable.Global */
body .vi { color: #19469D } /* Name.Variable.Instance */
body .il { color: #666666 } /* Literal.Number.Integer.Long */

View File

@ -0,0 +1,101 @@
<!DOCTYPE html> <html> <head> <title>pkginfo.js</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> pkginfo.js </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> </td> <td class="code"> <div class="highlight"><pre><span class="cm">/*</span>
<span class="cm"> * pkginfo.js: Top-level include for the pkginfo module</span>
<span class="cm"> *</span>
<span class="cm"> * (C) 2011, Charlie Robbins</span>
<span class="cm"> *</span>
<span class="cm"> */</span>
<span class="kd">var</span> <span class="nx">fs</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;fs&#39;</span><span class="p">),</span>
<span class="nx">path</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;path&#39;</span><span class="p">);</span></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">&#182;</a> </div> <h3>function pkginfo ([options, 'property', 'property' ..])</h3>
<h4>@pmodule {Module} Parent module to read from.</h4>
<h4>@options {Object|Array|string} <strong>Optional</strong> Options used when exposing properties.</h4>
<h4>@arguments {string...} <strong>Optional</strong> Specified properties to expose.</h4>
<p>Exposes properties from the package.json file for the parent module on
it's exports. Valid usage:</p>
<p><code>require('pkginfo')()</code></p>
<p><code>require('pkginfo')('version', 'author');</code></p>
<p><code>require('pkginfo')(['version', 'author']);</code></p>
<p><code>require('pkginfo')({ include: ['version', 'author'] });</code></p> </td> <td class="code"> <div class="highlight"><pre><span class="kd">var</span> <span class="nx">pkginfo</span> <span class="o">=</span> <span class="nx">module</span><span class="p">.</span><span class="nx">exports</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">pmodule</span><span class="p">,</span> <span class="nx">options</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">args</span> <span class="o">=</span> <span class="p">[].</span><span class="nx">slice</span><span class="p">.</span><span class="nx">call</span><span class="p">(</span><span class="nx">arguments</span><span class="p">,</span> <span class="mi">2</span><span class="p">).</span><span class="nx">filter</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">arg</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="k">typeof</span> <span class="nx">arg</span> <span class="o">===</span> <span class="s1">&#39;string&#39;</span><span class="p">;</span>
<span class="p">});</span>
</pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">&#182;</a> </div> <p><strong>Parse variable arguments</strong></p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">if</span> <span class="p">(</span><span class="nb">Array</span><span class="p">.</span><span class="nx">isArray</span><span class="p">(</span><span class="nx">options</span><span class="p">))</span> <span class="p">{</span></pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-4">&#182;</a> </div> <p>If the options passed in is an Array assume that
it is the Array of properties to expose from the
on the package.json file on the parent module.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">options</span> <span class="o">=</span> <span class="p">{</span> <span class="nx">include</span><span class="o">:</span> <span class="nx">options</span> <span class="p">};</span>
<span class="p">}</span>
<span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="k">typeof</span> <span class="nx">options</span> <span class="o">===</span> <span class="s1">&#39;string&#39;</span><span class="p">)</span> <span class="p">{</span></pre></div> </td> </tr> <tr id="section-5"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-5">&#182;</a> </div> <p>Otherwise if the first argument is a string, then
assume that it is the first property to expose from
the package.json file on the parent module.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">options</span> <span class="o">=</span> <span class="p">{</span> <span class="nx">include</span><span class="o">:</span> <span class="p">[</span><span class="nx">options</span><span class="p">]</span> <span class="p">};</span>
<span class="p">}</span>
</pre></div> </td> </tr> <tr id="section-6"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-6">&#182;</a> </div> <p><strong>Setup default options</strong></p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">options</span> <span class="o">=</span> <span class="nx">options</span> <span class="o">||</span> <span class="p">{</span> <span class="nx">include</span><span class="o">:</span> <span class="p">[]</span> <span class="p">};</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">args</span><span class="p">.</span><span class="nx">length</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span></pre></div> </td> </tr> <tr id="section-7"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-7">&#182;</a> </div> <p>If additional string arguments have been passed in
then add them to the properties to expose on the
parent module. </p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">options</span><span class="p">.</span><span class="nx">include</span> <span class="o">=</span> <span class="nx">options</span><span class="p">.</span><span class="nx">include</span><span class="p">.</span><span class="nx">concat</span><span class="p">(</span><span class="nx">args</span><span class="p">);</span>
<span class="p">}</span>
<span class="kd">var</span> <span class="nx">pkg</span> <span class="o">=</span> <span class="nx">pkginfo</span><span class="p">.</span><span class="nx">read</span><span class="p">(</span><span class="nx">pmodule</span><span class="p">,</span> <span class="nx">options</span><span class="p">.</span><span class="nx">dir</span><span class="p">).</span><span class="kr">package</span><span class="p">;</span>
<span class="nb">Object</span><span class="p">.</span><span class="nx">keys</span><span class="p">(</span><span class="nx">pkg</span><span class="p">).</span><span class="nx">forEach</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">key</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">options</span><span class="p">.</span><span class="nx">include</span><span class="p">.</span><span class="nx">length</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="o">&amp;&amp;</span> <span class="o">!~</span><span class="nx">options</span><span class="p">.</span><span class="nx">include</span><span class="p">.</span><span class="nx">indexOf</span><span class="p">(</span><span class="nx">key</span><span class="p">))</span> <span class="p">{</span>
<span class="k">return</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">pmodule</span><span class="p">.</span><span class="nx">exports</span><span class="p">[</span><span class="nx">key</span><span class="p">])</span> <span class="p">{</span>
<span class="nx">pmodule</span><span class="p">.</span><span class="nx">exports</span><span class="p">[</span><span class="nx">key</span><span class="p">]</span> <span class="o">=</span> <span class="nx">pkg</span><span class="p">[</span><span class="nx">key</span><span class="p">];</span>
<span class="p">}</span>
<span class="p">});</span>
<span class="k">return</span> <span class="nx">pkginfo</span><span class="p">;</span>
<span class="p">};</span></pre></div> </td> </tr> <tr id="section-8"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-8">&#182;</a> </div> <h3>function find (dir)</h3>
<h4>@pmodule {Module} Parent module to read from.</h4>
<h4>@dir {string} <strong>Optional</strong> Directory to start search from.</h4>
<p>Searches up the directory tree from <code>dir</code> until it finds a directory
which contains a <code>package.json</code> file. </p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">pkginfo</span><span class="p">.</span><span class="nx">find</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">pmodule</span><span class="p">,</span> <span class="nx">dir</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">dir</span> <span class="o">=</span> <span class="nx">dir</span> <span class="o">||</span> <span class="nx">pmodule</span><span class="p">.</span><span class="nx">filename</span><span class="p">;</span>
<span class="nx">dir</span> <span class="o">=</span> <span class="nx">path</span><span class="p">.</span><span class="nx">dirname</span><span class="p">(</span><span class="nx">dir</span><span class="p">);</span>
<span class="kd">var</span> <span class="nx">files</span> <span class="o">=</span> <span class="nx">fs</span><span class="p">.</span><span class="nx">readdirSync</span><span class="p">(</span><span class="nx">dir</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="o">~</span><span class="nx">files</span><span class="p">.</span><span class="nx">indexOf</span><span class="p">(</span><span class="s1">&#39;package.json&#39;</span><span class="p">))</span> <span class="p">{</span>
<span class="k">return</span> <span class="nx">path</span><span class="p">.</span><span class="nx">join</span><span class="p">(</span><span class="nx">dir</span><span class="p">,</span> <span class="s1">&#39;package.json&#39;</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">dir</span> <span class="o">===</span> <span class="s1">&#39;/&#39;</span><span class="p">)</span> <span class="p">{</span>
<span class="k">throw</span> <span class="k">new</span> <span class="nb">Error</span><span class="p">(</span><span class="s1">&#39;Could not find package.json up from: &#39;</span> <span class="o">+</span> <span class="nx">dir</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">return</span> <span class="nx">pkginfo</span><span class="p">.</span><span class="nx">find</span><span class="p">(</span><span class="nx">dir</span><span class="p">);</span>
<span class="p">};</span></pre></div> </td> </tr> <tr id="section-9"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-9">&#182;</a> </div> <h3>function read (pmodule, dir)</h3>
<h4>@pmodule {Module} Parent module to read from.</h4>
<h4>@dir {string} <strong>Optional</strong> Directory to start search from.</h4>
<p>Searches up the directory tree from <code>dir</code> until it finds a directory
which contains a <code>package.json</code> file and returns the package information.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">pkginfo</span><span class="p">.</span><span class="nx">read</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">pmodule</span><span class="p">,</span> <span class="nx">dir</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">dir</span> <span class="o">=</span> <span class="nx">pkginfo</span><span class="p">.</span><span class="nx">find</span><span class="p">(</span><span class="nx">pmodule</span><span class="p">,</span> <span class="nx">dir</span><span class="p">);</span>
<span class="kd">var</span> <span class="nx">data</span> <span class="o">=</span> <span class="nx">fs</span><span class="p">.</span><span class="nx">readFileSync</span><span class="p">(</span><span class="nx">dir</span><span class="p">).</span><span class="nx">toString</span><span class="p">();</span>
<span class="k">return</span> <span class="p">{</span>
<span class="nx">dir</span><span class="o">:</span> <span class="nx">dir</span><span class="p">,</span>
<span class="kr">package</span><span class="o">:</span> <span class="nx">JSON</span><span class="p">.</span><span class="nx">parse</span><span class="p">(</span><span class="nx">data</span><span class="p">)</span>
<span class="p">};</span>
<span class="p">};</span></pre></div> </td> </tr> <tr id="section-10"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-10">&#182;</a> </div> <p>Call <code>pkginfo</code> on this module and expose version.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">pkginfo</span><span class="p">(</span><span class="nx">module</span><span class="p">,</span> <span class="p">{</span>
<span class="nx">dir</span><span class="o">:</span> <span class="nx">__dirname</span><span class="p">,</span>
<span class="nx">include</span><span class="o">:</span> <span class="p">[</span><span class="s1">&#39;version&#39;</span><span class="p">],</span>
<span class="nx">target</span><span class="o">:</span> <span class="nx">pkginfo</span>
<span class="p">});</span>
</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>

View File

@ -0,0 +1,19 @@
/*
* all-properties.js: Sample of including all properties from a package.json file
*
* (C) 2011, Charlie Robbins
*
*/
var util = require('util'),
pkginfo = require('../lib/pkginfo')(module);
exports.someFunction = function () {
console.log('some of your custom logic here');
};
console.log('Inspecting module:');
console.dir(module.exports);
console.log('\nAll exports exposed:');
console.error(Object.keys(module.exports));

View File

@ -0,0 +1,20 @@
/*
* array-argument.js: Sample of including specific properties from a package.json file
* using Array argument syntax.
*
* (C) 2011, Charlie Robbins
*
*/
var util = require('util'),
pkginfo = require('../lib/pkginfo')(module, ['version', 'author']);
exports.someFunction = function () {
console.log('some of your custom logic here');
};
console.log('Inspecting module:');
console.dir(module.exports);
console.log('\nAll exports exposed:');
console.error(Object.keys(module.exports));

View File

@ -0,0 +1,19 @@
/*
* multiple-properties.js: Sample of including multiple properties from a package.json file
*
* (C) 2011, Charlie Robbins
*
*/
var util = require('util'),
pkginfo = require('../lib/pkginfo')(module, 'version', 'author');
exports.someFunction = function () {
console.log('some of your custom logic here');
};
console.log('Inspecting module:');
console.dir(module.exports);
console.log('\nAll exports exposed:');
console.error(Object.keys(module.exports));

View File

@ -0,0 +1,22 @@
/*
* object-argument.js: Sample of including specific properties from a package.json file
* using Object argument syntax.
*
* (C) 2011, Charlie Robbins
*
*/
var util = require('util'),
pkginfo = require('../lib/pkginfo')(module, {
include: ['version', 'author']
});
exports.someFunction = function () {
console.log('some of your custom logic here');
};
console.log('Inspecting module:');
console.dir(module.exports);
console.log('\nAll exports exposed:');
console.error(Object.keys(module.exports));

View File

@ -0,0 +1,10 @@
{
"name": "simple-app",
"description": "A test fixture for pkginfo",
"version": "0.1.0",
"author": "Charlie Robbins <charlie.robbins@gmail.com>",
"keywords": ["test", "fixture"],
"main": "./index.js",
"scripts": { "test": "vows test/*-test.js --spec" },
"engines": { "node": ">= 0.4.0" }
}

View File

@ -0,0 +1,19 @@
/*
* single-property.js: Sample of including a single specific properties from a package.json file
*
* (C) 2011, Charlie Robbins
*
*/
var util = require('util'),
pkginfo = require('../lib/pkginfo')(module, 'version');
exports.someFunction = function () {
console.log('some of your custom logic here');
};
console.log('Inspecting module:');
console.dir(module.exports);
console.log('\nAll exports exposed:');
console.error(Object.keys(module.exports));

View File

@ -0,0 +1,132 @@
/*
* pkginfo.js: Top-level include for the pkginfo module
*
* (C) 2011, Charlie Robbins
*
*/
var fs = require('fs'),
path = require('path');
//
// ### function pkginfo ([options, 'property', 'property' ..])
// #### @pmodule {Module} Parent module to read from.
// #### @options {Object|Array|string} **Optional** Options used when exposing properties.
// #### @arguments {string...} **Optional** Specified properties to expose.
// Exposes properties from the package.json file for the parent module on
// it's exports. Valid usage:
//
// `require('pkginfo')()`
//
// `require('pkginfo')('version', 'author');`
//
// `require('pkginfo')(['version', 'author']);`
//
// `require('pkginfo')({ include: ['version', 'author'] });`
//
var pkginfo = module.exports = function (pmodule, options) {
var args = [].slice.call(arguments, 2).filter(function (arg) {
return typeof arg === 'string';
});
//
// **Parse variable arguments**
//
if (Array.isArray(options)) {
//
// If the options passed in is an Array assume that
// it is the Array of properties to expose from the
// on the package.json file on the parent module.
//
options = { include: options };
}
else if (typeof options === 'string') {
//
// Otherwise if the first argument is a string, then
// assume that it is the first property to expose from
// the package.json file on the parent module.
//
options = { include: [options] };
}
//
// **Setup default options**
//
options = options || { include: [] };
if (args.length > 0) {
//
// If additional string arguments have been passed in
// then add them to the properties to expose on the
// parent module.
//
options.include = options.include.concat(args);
}
var pkg = pkginfo.read(pmodule, options.dir).package;
Object.keys(pkg).forEach(function (key) {
if (options.include.length > 0 && !~options.include.indexOf(key)) {
return;
}
if (!pmodule.exports[key]) {
pmodule.exports[key] = pkg[key];
}
});
return pkginfo;
};
//
// ### function find (dir)
// #### @pmodule {Module} Parent module to read from.
// #### @dir {string} **Optional** Directory to start search from.
// Searches up the directory tree from `dir` until it finds a directory
// which contains a `package.json` file.
//
pkginfo.find = function (pmodule, dir) {
dir = dir || pmodule.filename;
dir = path.dirname(dir);
var files = fs.readdirSync(dir);
if (~files.indexOf('package.json')) {
return path.join(dir, 'package.json');
}
if (dir === '/') {
throw new Error('Could not find package.json up from: ' + dir);
}
else if (!dir || dir === '.') {
throw new Error('Cannot find package.json from unspecified directory');
}
return pkginfo.find(pmodule, dir);
};
//
// ### function read (pmodule, dir)
// #### @pmodule {Module} Parent module to read from.
// #### @dir {string} **Optional** Directory to start search from.
// Searches up the directory tree from `dir` until it finds a directory
// which contains a `package.json` file and returns the package information.
//
pkginfo.read = function (pmodule, dir) {
dir = pkginfo.find(pmodule, dir);
var data = fs.readFileSync(dir).toString();
return {
dir: dir,
package: JSON.parse(data)
};
};
//
// Call `pkginfo` on this module and expose version.
//
pkginfo(module, {
dir: __dirname,
include: ['version'],
target: pkginfo
});

View File

@ -0,0 +1,36 @@
{
"name": "pkginfo",
"version": "0.2.3",
"description": "An easy way to expose properties on a module from a package.json",
"author": {
"name": "Charlie Robbins",
"email": "charlie.robbins@gmail.com"
},
"repository": {
"type": "git",
"url": "http://github.com/indexzero/node-pkginfo.git"
},
"keywords": [
"info",
"tools",
"package.json"
],
"devDependencies": {
"vows": "0.6.x"
},
"main": "./lib/pkginfo",
"scripts": {
"test": "vows test/*-test.js --spec"
},
"engines": {
"node": ">= 0.4.0"
},
"readme": "# node-pkginfo\n\nAn easy way to expose properties on a module from a package.json\n\n## Installation\n\n### Installing npm (node package manager)\n```\n curl http://npmjs.org/install.sh | sh\n```\n\n### Installing pkginfo\n```\n [sudo] npm install pkginfo\n```\n\n## Motivation\nHow often when writing node.js modules have you written the following line(s) of code? \n\n* Hard code your version string into your code\n\n``` js\n exports.version = '0.1.0';\n```\n\n* Programmatically expose the version from the package.json\n\n``` js\n exports.version = JSON.parse(fs.readFileSync('/path/to/package.json', 'utf8')).version;\n```\n\nIn other words, how often have you wanted to expose basic information from your package.json onto your module programmatically? **WELL NOW YOU CAN!**\n\n## Usage\n\nUsing `pkginfo` is idiot-proof, just require and invoke it. \n\n``` js\n var pkginfo = require('pkginfo')(module);\n \n console.dir(module.exports);\n```\n\nBy invoking the `pkginfo` module all of the properties in your `package.json` file will be automatically exposed on the callee module (i.e. the parent module of `pkginfo`). \n\nHere's a sample of the output:\n\n```\n { name: 'simple-app',\n description: 'A test fixture for pkginfo',\n version: '0.1.0',\n author: 'Charlie Robbins <charlie.robbins@gmail.com>',\n keywords: [ 'test', 'fixture' ],\n main: './index.js',\n scripts: { test: 'vows test/*-test.js --spec' },\n engines: { node: '>= 0.4.0' } }\n```\n\n### Expose specific properties\nIf you don't want to expose **all** properties on from your `package.json` on your module then simple pass those properties to the `pkginfo` function:\n\n``` js\n var pkginfo = require('pkginfo')(module, 'version', 'author');\n \n console.dir(module.exports);\n```\n\n```\n { version: '0.1.0',\n author: 'Charlie Robbins <charlie.robbins@gmail.com>' }\n```\n\nIf you're looking for further usage see the [examples][0] included in this repository. \n\n## Run Tests\nTests are written in [vows][1] and give complete coverage of all APIs.\n\n```\n vows test/*-test.js --spec\n```\n\n[0]: https://github.com/indexzero/node-pkginfo/tree/master/examples\n[1]: http://vowsjs.org\n\n#### Author: [Charlie Robbins](http://nodejitsu.com)",
"readmeFilename": "README.md",
"_id": "pkginfo@0.2.3",
"dist": {
"shasum": "0457c06646c236f7dab060461d31cb2121f040db"
},
"_from": "pkginfo@0.2.x",
"_resolved": "https://registry.npmjs.org/pkginfo/-/pkginfo-0.2.3.tgz"
}

View File

@ -0,0 +1,69 @@
/*
* pkginfo-test.js: Tests for the pkginfo module.
*
* (C) 2011, Charlie Robbins
*
*/
var assert = require('assert'),
exec = require('child_process').exec,
fs = require('fs'),
path = require('path'),
vows = require('vows'),
pkginfo = require('../lib/pkginfo');
function assertProperties (source, target) {
assert.lengthOf(source, target.length + 1);
target.forEach(function (prop) {
assert.isTrue(!!~source.indexOf(prop));
});
}
function testExposes (options) {
return {
topic: function () {
exec('node ' + path.join(__dirname, '..', 'examples', options.script), this.callback);
},
"should expose that property correctly": function (err, stdout, stderr) {
assert.isNull(err);
var exposed = stderr.match(/'(\w+)'/ig).map(function (p) {
return p.substring(1, p.length - 1);
});
return !options.assert
? assertProperties(exposed, options.properties)
: options.assert(exposed);
}
}
}
vows.describe('pkginfo').addBatch({
"When using the pkginfo module": {
"and passed a single `string` argument": testExposes({
script: 'single-property.js',
properties: ['version']
}),
"and passed multiple `string` arguments": testExposes({
script: 'multiple-properties.js',
properties: ['version', 'author']
}),
"and passed an `object` argument": testExposes({
script: 'object-argument.js',
properties: ['version', 'author']
}),
"and passed an `array` argument": testExposes({
script: 'array-argument.js',
properties: ['version', 'author']
}),
"and passed no arguments": testExposes({
script: 'all-properties.js',
assert: function (exposed) {
var pkg = fs.readFileSync(path.join(__dirname, '..', 'examples', 'package.json')).toString(),
keys = Object.keys(JSON.parse(pkg));
assertProperties(exposed, keys);
}
})
}
}).export(module);

53
node_modules/passport/package.json generated vendored Normal file

File diff suppressed because one or more lines are too long