function BadRequestError(message) { Error.call(this); Error.captureStackTrace(this, arguments.callee); this.name = 'BadRequestError'; this.message = message || null; }
n/a
function Strategy(options, verify) { if (typeof options == 'function') { verify = options; options = {}; } if (!verify) throw new Error('local authentication strategy requires a verify function'); this._apiKeyField = options.apiKeyField || 'apikey'; passport.Strategy.call(this); this.name = 'localapikey'; this._verify = verify; this._passReqToCallback = options.passReqToCallback; }
n/a
function Strategy() { }
n/a
function Strategy(options, verify) { if (typeof options == 'function') { verify = options; options = {}; } if (!verify) throw new Error('local authentication strategy requires a verify function'); this._apiKeyField = options.apiKeyField || 'apikey'; passport.Strategy.call(this); this.name = 'localapikey'; this._verify = verify; this._passReqToCallback = options.passReqToCallback; }
n/a
function Strategy() { }
n/a
authenticate = function (req, options) { options = options || {}; var apikey = lookup(req.body, this._apiKeyField) || lookup(req.query, this._apiKeyField); if (!apikey) { return this.fail(new BadRequestError(options.badRequestMessage || 'Missing API Key')); } var self = this; function verified(err, user, info) { if (err) { return self.error(err); } if (!user) { return self.fail(info); } self.success(user, info); } if (self._passReqToCallback) { this._verify(req, apikey, verified); } else { this._verify(apikey, verified); } function lookup(obj, field) { if (!obj) { return null; } var chain = field.split(']').join('').split('['); for (var i = 0, len = chain.length; i < len; i++) { var prop = obj[chain[i]]; if (typeof(prop) === 'undefined') { return null; } if (typeof(prop) !== 'object') { return prop; } obj = prop; } return null; } }
...
{
"name": "sudhakarmani",
"email": "mail4sudhakar@gmail.com"
}
],
"name": "passport-localapikey",
"optionalDependencies": {},
"readme": "# Passport-LocalAPIKey\n\n[Passport](http://passportjs.org/) strategy for authenticating with a apikey
.\n\nThis module lets you authenticate using a apikey in your Node.js\napplications which is used to build rest apis.By plugging into Passport, local apikey authentication can be easily and\nunobtrusively integrated into any application or framework that supports\n[Connect](http://www.senchalabs.org/connect/)-style middleware, including\n[Express](http://expressjs.com/).\n\n## Installation\n\n $ npm install passport-localapikey\n\n## Usage\n\n#### Configure Strategy\n\nThe local api key authentication strategy authenticates users using a apikey. \nThe strategy requires a `verify` callback, which accepts these\ncredentials and calls `done` providing a user.\n\n passport.use(new LocalAPIKeyStrategy(\n function(apikey, done) {\n User.findOne({ apikey: apikey }, function (err, user) {\n if (err) { return done(err); }\n if (!user) { return done(null, false); }\n return done(null, user);\n });\n }\n ));\n\n#### Authenticate Requests\n\nUse `passport.authenticate()`, specifying the `'localapikey'` strategy, to\nauthenticate requests.\n\nFor example, as route middleware in an [Express](http://expressjs.com/)\napplication:\n\n app.post('/api/authenticate', \n passport.authenticate('localapikey', { failureRedirect: '/api/unauthorized' }),\n function(req, res) {\n res.json({ message: \"Authenticated\" })\n });\n\n## Examples\n\n curl -v -d \"apikey=asdasjsdgfjkjhg\" http://127.0.0.1:3000/api/authenticate\n\n## Tests\n\n $ npm install --dev\n $ make test\n\n[](http://travis-ci.org/cholalabs/passport-localapikey)\n\n## Credits\n\n - [Sudhakar Mani](http://twitter.com/sudhakarmani)\n\n## License\n\n(The MIT License)\n\nCopyright (c) 2012 Sudhakar Mani\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of\nthis software and associated documentation files (the \"Software\"), to deal in\nthe Software without restriction, including without limitation the rights to\nuse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\nthe Software, and to permit persons to whom the Software is furnished to do so,\nsubject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\nFOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\nCOPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\nIN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\nCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n",
"repository": {
"type": "git",
"url": "git://github.com/cholalabs/passport-localapikey.git"
},
"scripts": {
"test": "NODE_PATH=lib node_modules/.bin/vows test/*-test.js"
},
...
function Strategy() { }
n/a
authenticate = function (req, options) { throw new Error('Strategy#authenticate must be overridden by subclass'); }
...
{
"name": "sudhakarmani",
"email": "mail4sudhakar@gmail.com"
}
],
"name": "passport-localapikey",
"optionalDependencies": {},
"readme": "# Passport-LocalAPIKey\n\n[Passport](http://passportjs.org/) strategy for authenticating with a apikey
.\n\nThis module lets you authenticate using a apikey in your Node.js\napplications which is used to build rest apis.By plugging into Passport, local apikey authentication can be easily and\nunobtrusively integrated into any application or framework that supports\n[Connect](http://www.senchalabs.org/connect/)-style middleware, including\n[Express](http://expressjs.com/).\n\n## Installation\n\n $ npm install passport-localapikey\n\n## Usage\n\n#### Configure Strategy\n\nThe local api key authentication strategy authenticates users using a apikey. \nThe strategy requires a `verify` callback, which accepts these\ncredentials and calls `done` providing a user.\n\n passport.use(new LocalAPIKeyStrategy(\n function(apikey, done) {\n User.findOne({ apikey: apikey }, function (err, user) {\n if (err) { return done(err); }\n if (!user) { return done(null, false); }\n return done(null, user);\n });\n }\n ));\n\n#### Authenticate Requests\n\nUse `passport.authenticate()`, specifying the `'localapikey'` strategy, to\nauthenticate requests.\n\nFor example, as route middleware in an [Express](http://expressjs.com/)\napplication:\n\n app.post('/api/authenticate', \n passport.authenticate('localapikey', { failureRedirect: '/api/unauthorized' }),\n function(req, res) {\n res.json({ message: \"Authenticated\" })\n });\n\n## Examples\n\n curl -v -d \"apikey=asdasjsdgfjkjhg\" http://127.0.0.1:3000/api/authenticate\n\n## Tests\n\n $ npm install --dev\n $ make test\n\n[](http://travis-ci.org/cholalabs/passport-localapikey)\n\n## Credits\n\n - [Sudhakar Mani](http://twitter.com/sudhakarmani)\n\n## License\n\n(The MIT License)\n\nCopyright (c) 2012 Sudhakar Mani\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of\nthis software and associated documentation files (the \"Software\"), to deal in\nthe Software without restriction, including without limitation the rights to\nuse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\nthe Software, and to permit persons to whom the Software is furnished to do so,\nsubject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\nFOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\nCOPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\nIN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\nCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n",
"repository": {
"type": "git",
"url": "git://github.com/cholalabs/passport-localapikey.git"
},
"scripts": {
"test": "NODE_PATH=lib node_modules/.bin/vows test/*-test.js"
},
...