Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

First commit.

  • Loading branch information...
commit c1eeab419096add6fe68d616bb41d0f35b231fde 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-http/*.js
+ dox \
+ --title Passport-HTTP \
+ --desc "HTTP Basic and Digest authentication strategies for Passport" \
+ $(shell find lib/passport-http/* -type f) > $@
+
+docclean:
+ rm -f docs/*.{1,html}
+
+.PHONY: test docs docclean
26 README.md
@@ -0,0 +1,26 @@
+# Passport-HTTP
+
+HTTP Basic and Digest authentication strategies for [Passport](https://github.com/jaredhanson/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.
15 lib/passport-http/index.js
@@ -0,0 +1,15 @@
+/**
+ * Module dependencies.
+ */
+var BasicStrategy = require('./strategies/basic');
+
+
+/**
+ * Framework version.
+ */
+exports.version = '0.1.0';
+
+/**
+ * Expose constructors.
+ */
+exports.BasicStrategy = BasicStrategy;
18 lib/passport-http/middleware/basic.js
@@ -0,0 +1,18 @@
+module.exports = function basic() {
+
+ return function basic(req, res, next) {
+ var authorization = req.headers['authorization'];
+ if (!authorization) { return next(); }
+
+ var parts = authorization.split(' ')
+ , scheme = parts[0]
+ , credentials = new Buffer(parts[1], 'base64').toString().split(':');
+
+ if ('Basic' != scheme) { return next(); }
+
+ req.auth = req.auth || {};
+ req.auth.userid = credentials[0];
+ req.auth.password = credentials[1];
+ next();
+ }
+}
43 lib/passport-http/strategies/basic.js
@@ -0,0 +1,43 @@
+/**
+ * Module dependencies.
+ */
+var passport = require('passport')
+ , util = require('util');
+
+
+/**
+ * `BasicStrategy` constructor.
+ *
+ * @api public
+ */
+function BasicStrategy(options, validate) {
+ options = options || {}
+ passport.Strategy.call(this);
+ this.name = 'basic';
+ this._validate = validate;
+
+ this.middleware.push(require('../middleware/basic')());
+}
+
+/**
+ * Inherit from `passport.Strategy`.
+ */
+util.inherits(BasicStrategy, passport.Strategy);
+
+BasicStrategy.prototype.authenticate = function(req) {
+ if (!req.auth || (!req.auth.userid && !req.auth.password)) {
+ return this.unauthorized();
+ }
+
+ var self = this;
+ this._validate(req.auth.userid, req.auth.password, function(err, user) {
+ if (err || !user) { return self.unauthorized(); }
+ self.success(user);
+ });
+}
+
+
+/**
+ * Expose `BasicStrategy`.
+ */
+module.exports = BasicStrategy;
16 package.json
@@ -0,0 +1,16 @@
+{
+ "name": "passport-http",
+ "version": "0.1.0",
+ "description": "HTTP Basic and Digest authentication strategies for Passport.",
+ "author": "Jared Hanson <jaredhanson@gmail.com> (http://www.jaredhanson.net/)",
+ "repository": {
+ "type": "git",
+ "url": "http://github.com/jaredhanson/passport-http.git"
+ },
+ "main": "./lib/passport-http",
+ "dependencies": {
+ "passport": ">= 0.0.1"
+ },
+ "engines": { "node": ">= 0.4.0" },
+ "keywords": ["passport", "http", "basic", "digest", "auth", "authn", "authentication"]
+}
Please sign in to comment.
Something went wrong with that request. Please try again.