Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

First commit.

  • Loading branch information...
commit 39f0a131457064b2c8bf6b5622bafb4ca22c1fcc 0 parents
@jaredhanson authored
2  .gitignore
@@ -0,0 +1,2 @@
+.DS_Store
+node_modules
8 .npmignore
@@ -0,0 +1,8 @@
+*.md
+.DS_Store
+.git*
+Makefile
+docs/
+examples/
+support/
+test/
20 LICENSE
@@ -0,0 +1,20 @@
+(The MIT License)
+
+Copyright (c) 2011 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.
19 Makefile
@@ -0,0 +1,19 @@
+NODE = node
+TEST = vows
+TESTS ?= test/*-test.js test/**/*-test.js
+
+test:
+ @NODE_ENV=test NODE_PATH=lib $(TEST) $(TEST_FLAGS) $(TESTS)
+
+docs: docs/api.html
+
+docs/api.html: lib/passport/*.js
+ dox \
+ --title Passport \
+ --desc "Authentication framework for Connect and Express" \
+ $(shell find lib/passport/* -type f) > $@
+
+docclean:
+ rm -f docs/*.{1,html}
+
+.PHONY: test docs docclean
32 README.md
@@ -0,0 +1,32 @@
+# Passport
+
+Passport is an authentication framework for [Connect](http://senchalabs.github.com/connect/)
+and [Express](http://nodejs.org), which is extensible through "plugins" known as
+_strategies_.
+
+## Installation
+
+ $ npm install passport
+
+## License
+
+(The MIT License)
+
+Copyright (c) 2011 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.
96 lib/passport/index.js
@@ -0,0 +1,96 @@
+/**
+ * Module dependencies.
+ */
+var fs = require('fs')
+ , path = require('path')
+ , Strategy = require('./strategy');
+
+
+/**
+ * `Passport` constructor.
+ *
+ * @api public
+ */
+function Passport() {
+ this._strategies = [];
+ this._middleware = [];
+};
+
+// TODO: Make it optional to name a strategy. If not named, it uses its default
+// name
+Passport.prototype.use = function(name, strategy) {
+ this._strategies.push(strategy);
+
+ var middleware = strategy.middleware;
+ if (middleware) {
+ if (Array.isArray(middleware)) {
+ this._middleware = this._middleware.concat(middleware);
+ } else {
+ this._middleware.push(middleware);
+ }
+ }
+};
+
+Passport.prototype.middleware = function() {
+ var self = this;
+
+ return function(req, res, next) {
+ var stack = self._middleware;
+
+ (function pass(i, err) {
+ if (err) { return next(err); }
+
+ var layer = stack[i];
+ if (!layer) { return next(); }
+
+ try {
+ layer(req, res, function(e) { pass(i + 1, e); } )
+ } catch (e) {
+ next(e);
+ }
+ })(0);
+ }
+};
+
+
+
+/**
+ * Export default singleton.
+ *
+ * @api public
+ */
+exports = module.exports = new Passport();
+
+/**
+ * Framework version.
+ */
+exports.version = '0.1.0';
+
+/**
+ * Expose constructors.
+ */
+exports.Passport = Passport;
+exports.Strategy = Strategy;
+
+/**
+ * Expose Connect middleware.
+ */
+exports.authenticate = require('./middleware/authenticate')(exports);
+
+
+
+/**
+ * Auto-load bundled strategies.
+ */
+exports.strategies = {};
+
+if (path.existsSync(__dirname + '/strategies')) {
+ fs.readdirSync(__dirname + '/strategies').forEach(function(filename) {
+ if (/\.js$/.test(filename)) {
+ var name = filename.substr(0, filename.lastIndexOf('.'));
+ exports.strategies.__defineGetter__(name, function(){
+ return require('./strategies/' + name);
+ });
+ }
+ });
+}
9 lib/passport/middleware/authenticate.js
@@ -0,0 +1,9 @@
+module.exports = function authenticate(passport) {
+
+ return function authenticate(req, res, next) {
+ // TODO: Allow the strategy (or strategies) to be selected by name.
+ var s = passport._strategies[0];
+ s._handle(req, res, next);
+ next();
+ }
+}
25 lib/passport/strategy.js
@@ -0,0 +1,25 @@
+/**
+ * Module dependencies.
+ */
+var util = require('util');
+
+
+/**
+ * `Strategy` constructor.
+ *
+ * @api public
+ */
+function Strategy(options) {
+ options = options || {};
+ this.name = options.name;
+}
+
+Strategy.prototype._handle = function(req, res, next) {
+ this.authenticate(req, res, next);
+}
+
+
+/**
+ * Expose `Strategy`.
+ */
+module.exports = Strategy;
15 package.json
@@ -0,0 +1,15 @@
+{
+ "name": "passport",
+ "version": "0.1.0",
+ "description": "Authentication framework for Connect and Express.",
+ "author": "Jared Hanson <jaredhanson@gmail.com> (http://www.jaredhanson.net/)",
+ "repository": {
+ "type": "git",
+ "url": "http://github.com/jaredhanson/passport.git"
+ },
+ "main": "./lib/passport",
+ "dependencies": {
+ },
+ "engines": { "node": ">= 0.4.0" },
+ "keywords": ["express", "connect", "auth", "authn", "authentication"]
+}
Please sign in to comment.
Something went wrong with that request. Please try again.