Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial commit of dummy authentication module.

  • Loading branch information...
commit 007ad02750b8a3bb2a25193adf6eb0bbfadea9e6 0 parents
Adrian Rossouw authored
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.
16 lib/passport-dummy/index.js
@@ -0,0 +1,16 @@
+/**
+ * Module dependencies.
+ */
+var Strategy = require('./strategy');
+
+
+/**
+ * Framework version.
+ */
+exports.version = '0.1.0';
+
+/**
+ * Expose constructors.
+ */
+exports.Strategy = Strategy;
+
79 lib/passport-dummy/strategy.js
@@ -0,0 +1,79 @@
+/**
+* Module dependencies.
+*/
+var passport = require('passport')
+, util = require('util');
+
+
+/**
+* `Strategy` constructor.
+*
+* The dummy authentication strategy automatically authenticates requests.
+*
+* Applications must supply a `verify` callback which calls the `done` callback
+* supplying a `user`, which should be set to `false` if the credentials are
+* not valid.
+* If an exception occured, `err` should be set.
+*
+* Optionally, `options` can be used to change the fields in which the
+* credentials are found.
+*
+* Options:
+* - `allow` Successfully authenticate, defaults to _true_
+*
+* Examples:
+*
+* passport.use(new DummyStrategy(
+* function(done) {
+* var user = { username: 'dummy' }
+* done(null, user);
+* }
+* ));
+*
+* @param {Object} options
+* @param {Function} verify
+* @api public
+*/
+function Strategy(options, verify) {
+ if (typeof options == 'function') {
+ verify = options;
+ options = {};
+ }
+ if (!verify) throw new Error('dummy authentication strategy requires a verify function');
+
+ this._allow = options.allow || true;
+
+ passport.Strategy.call(this);
+ this.name = 'dummy';
+ this.verify = verify;
+}
+
+/**
+* Inherit from `passport.Strategy`.
+*/
+util.inherits(Strategy, passport.Strategy);
+
+/**
+* Authenticate request.
+*
+* @param {Object} req
+* @api protected
+*/
+Strategy.prototype.authenticate = function(req) {
+ if (!this._allow) {
+ return this.fail();
+ }
+
+ var self = this;
+ this.verify(function(err, user) {
+ if (err) { return self.error(err); }
+ if (!user) { return self.fail(); }
+ self.success(user, {});
+ });
+}
+
+
+/**
+* Expose `Strategy`.
+*/
+module.exports = Strategy;
12 package.json
@@ -0,0 +1,12 @@
+{
+ "name": "passport-dummy",
+ "version": "0.0.1",
+ "description": "Dummy authentication strategy for Passport.",
+ "author": "Adrian Rossouw <adrian@developmentseed.org> (http://www.jaredhanson.net/)",
+ "main": "./lib/passport-dummy",
+ "dependencies": {
+ "passport": ">= 0.1.1"
+ },
+ "engines": { "node": ">= 0.4.0" },
+ "keywords": ["passport", "auth", "authentication", "identity"]
+}
44 readme.md
@@ -0,0 +1,44 @@
+# Passport-Dummy
+
+[Passport](https://github.com/jaredhanson/passport) strategy for dummy authentication.
+
+## Installation
+
+ $ npm install passport-dummy
+
+## Usage
+
+#### Configure Strategy
+
+The dummy authentication strategy authenticates or denies all requests based on the
+'allow' option passed to it.
+
+ passport.use(new DummyStrategy(
+ function(done) {
+ return done(null, {username: 'dummy'});
+ }
+ ));
+
+#### Authenticate Requests
+
+Use `passport.authenticate()`, specifying the `'dummy'` strategy, to
+authenticate requests.
+
+For example, as route middleware in an [Express](http://expressjs.com/)
+application:
+
+ app.post('/login',
+ passport.authenticate('dummy', { failureRedirect: '/login' }),
+ function(req, res) {
+ res.redirect('/');
+ });
+
+
+## Credits
+
+ - [Adrian Rossouw](http://github.com/Vertice)
+ - [Jared Hanson](http://github.com/jaredhanson)
+
+## License
+
+(The MIT License)
Please sign in to comment.
Something went wrong with that request. Please try again.