{"_id":"mongoose-auth","_rev":"56-643f1b18cf287e0b3567428533a3816d","name":"mongoose-auth","description":"User authentication plugin for mongoose node.js orm","dist-tags":{"latest":"0.0.12"},"versions":{"0.0.1":{"name":"mongoose-auth","description":"User authentication plugin for mongoose node.js orm","version":"0.0.1","homepage":"https://github.com/bnoguchi/mongoose-auth/","repository":{"type":"git","url":"git://github.com/bnoguchi/mongoose-auth.git"},"author":{"name":"Brian Noguchi","email":"brian.noguchi@gmail.com","url":"https://github.com/bnoguchi/"},"main":"./index.js","directories":{"lib":"."},"dependencies":{"bcrypt":">=0.1.2","mongoose":">=1.1.24","everyauth":">=0.0.4"},"scripts":{"test":"make test"},"engines":{"node":">=0.4.1"},"_id":"mongoose-auth@0.0.1","_engineSupported":true,"_npmVersion":"0.3.15","_nodeVersion":"v0.4.5","files":[""],"_defaultsLoaded":true,"dist":{"shasum":"ab700e95509ce114d7791bdee34e6859c4923c24","tarball":"https://registry.npmjs.org/mongoose-auth/-/mongoose-auth-0.0.1.tgz","integrity":"sha512-zYMdt1w85IDW610Q1BFZ9By9u/XzwXuSfFnQsAZcwhR19kZmlaG5mviEsnNf+CdHmOJB2+OTdAMegwGy05sV9A==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDxQIiSFoduXK/WwpbXIIl18TzDzk/ZldskDyB882oYBQIhANVH8Mz14NPagHJSn3Wsw+3eOxVohaK8LCFFkKT4YVM8"}]}},"0.0.2":{"name":"mongoose-auth","description":"User authentication plugin for mongoose node.js orm","version":"0.0.2","homepage":"https://github.com/bnoguchi/mongoose-auth/","repository":{"type":"git","url":"git://github.com/bnoguchi/mongoose-auth.git"},"author":{"name":"Brian Noguchi","email":"brian.noguchi@gmail.com","url":"https://github.com/bnoguchi/"},"main":"./index.js","directories":{"lib":"."},"dependencies":{"bcrypt":">=0.1.2","mongoose":">=1.1.24","everyauth":">=0.0.4"},"scripts":{"test":"make test"},"engines":{"node":">=0.4.1"},"_id":"mongoose-auth@0.0.2","_engineSupported":true,"_npmVersion":"0.3.15","_nodeVersion":"v0.4.5","files":[""],"_defaultsLoaded":true,"dist":{"shasum":"740453c7422587e9625715479ba0adfbb9770df0","tarball":"https://registry.npmjs.org/mongoose-auth/-/mongoose-auth-0.0.2.tgz","integrity":"sha512-vlA5aRcqnHh8t435NV6K1vGL5UDDjmiWMVEHibg5TO++Y64ybjfSwHGDF7KyGdgxKRIQS28+pLpMzDqUFsdz8A==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCPc/Um16uG/3oE01C8Fy2pXi55j3SaT4cXbNZMLn4pMgIhAOcu1sAsu4kom/u8IcdNLmLlCKEpf9d5dEL5DoGeLavD"}]}},"0.0.3":{"name":"mongoose-auth","description":"User authentication plugin for mongoose node.js orm","version":"0.0.3","homepage":"https://github.com/bnoguchi/mongoose-auth/","repository":{"type":"git","url":"git://github.com/bnoguchi/mongoose-auth.git"},"author":{"name":"Brian Noguchi","email":"brian.noguchi@gmail.com","url":"https://github.com/bnoguchi/"},"main":"./index.js","directories":{"lib":"."},"dependencies":{"bcrypt":">=0.2.0","mongoose":">=1.1.24","everyauth":">=0.0.6"},"engines":{"node":"0.4.x"},"_id":"mongoose-auth@0.0.3","_engineSupported":true,"_npmVersion":"0.3.15","_nodeVersion":"v0.4.5","files":[""],"_defaultsLoaded":true,"dist":{"shasum":"33d5e52c37cfe5fbc4c08bdc64a93e65509bc5e9","tarball":"https://registry.npmjs.org/mongoose-auth/-/mongoose-auth-0.0.3.tgz","integrity":"sha512-XGY3lePdHkw240fy3HxwayiZMvefzLhPLUW9Hlfc9+j1N8Y+gJRo4mecVtQx0NAe6iowKWKn9zTo72sWbHzCgQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIEyfwYJV6mR3BXKbYajylvpJEngDtgWugd7RlgrNiMjSAiB3jBDTGoSSPa9DhAtd9T/bLDIt52V1Mw/im9MRPXqpJQ=="}]}},"0.0.4":{"name":"mongoose-auth","description":"User authentication plugin for mongoose node.js orm","version":"0.0.4","homepage":"https://github.com/bnoguchi/mongoose-auth/","repository":{"type":"git","url":"git://github.com/bnoguchi/mongoose-auth.git"},"author":{"name":"Brian Noguchi","email":"brian.noguchi@gmail.com","url":"https://github.com/bnoguchi/"},"main":"./index.js","directories":{"lib":"."},"dependencies":{"bcrypt":">=0.2.0","mongoose":">=1.2.0","everyauth":">=0.0.8"},"engines":{"node":"0.4.x"},"_id":"mongoose-auth@0.0.4","_engineSupported":true,"_npmVersion":"0.3.15","_nodeVersion":"v0.4.5","files":[""],"_defaultsLoaded":true,"dist":{"shasum":"e8ca5fe33051857de00a7caabcceea9c36dc06b1","tarball":"https://registry.npmjs.org/mongoose-auth/-/mongoose-auth-0.0.4.tgz","integrity":"sha512-vz7st+P9U4BTwepZm6nVZpIfW1b4e+7geHJMJCJSVUj2AgHqB8y0pNQNYQAxDPML9EPlTNfnVKZamYIVWTLKLQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDOcu2H75nmPMydUeFH8vJrtQI+vvmLIPGr+rdABXd6MQIgLuPfL/6mKkxOcEyXho0ZdK1TTyeuC2PQEN/P0y2fEyM="}]}},"0.0.5":{"name":"mongoose-auth","description":"User authentication plugin for mongoose node.js orm","version":"0.0.5","homepage":"https://github.com/bnoguchi/mongoose-auth/","repository":{"type":"git","url":"git://github.com/bnoguchi/mongoose-auth.git"},"author":{"name":"Brian Noguchi","email":"brian.noguchi@gmail.com","url":"https://github.com/bnoguchi/"},"main":"./index.js","directories":{"lib":"."},"dependencies":{"bcrypt":">=0.2.0","mongoose":">=1.2.0","everyauth":">=0.0.9","mongoose-types":">=1.0.3"},"engines":{"node":"0.4.x"},"devDependencies":{},"_id":"mongoose-auth@0.0.5","_engineSupported":true,"_npmVersion":"1.0.1rc8","_nodeVersion":"v0.4.6","_defaultsLoaded":true,"dist":{"shasum":"abee69a3e054b3aa0de9ca3b01c201a762915b7a","tarball":"https://registry.npmjs.org/mongoose-auth/-/mongoose-auth-0.0.5.tgz","integrity":"sha512-IWpFGChmsYlfLjyPYF4i+y9IXoNugf6Z//13KzncDNbmY9N4jEsmwkA9jkrF3p0IJ+KBHJYoHSoyteinwr6ePQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCICD6uj+MSpHO8zoasGMik3f2OmFTRkPo8J72U97ohk8EAiAgS3wGMa/BVNc8RHfUPZPL/CXw9SU8mkNS/pOMLMLLRA=="}]}},"0.0.6":{"name":"mongoose-auth","description":"User authentication plugin for mongoose node.js orm","version":"0.0.6","homepage":"https://github.com/bnoguchi/mongoose-auth/","repository":{"type":"git","url":"git://github.com/bnoguchi/mongoose-auth.git"},"author":{"name":"Brian Noguchi","email":"brian.noguchi@gmail.com","url":"https://github.com/bnoguchi/"},"main":"./index.js","directories":{"lib":"."},"dependencies":{"bcrypt":">=0.2.0","mongoose":">=1.3.0","everyauth":">=0.1.6","mongoose-types":">=1.0.3"},"engines":{"node":"0.4.x"},"devDependencies":{},"_id":"mongoose-auth@0.0.6","_engineSupported":true,"_npmVersion":"1.0.1rc9","_nodeVersion":"v0.4.7","_defaultsLoaded":true,"dist":{"shasum":"9e5b39971cc5c580c11bb37b47db4496c23d5fb7","tarball":"https://registry.npmjs.org/mongoose-auth/-/mongoose-auth-0.0.6.tgz","integrity":"sha512-NSbLWr0Fye3U0kdceAE9UFkkZX+rMF3gwH8LH09HeU1F9NtSqVz9Czmm/eOxFWbUE6cj+MHzQjCOU6Ow9F17IQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCMD+yIqDPbpdGqCqPSZ0pmIwHCQvzhxoilLwXuaYfNPwIgVmyUgPGapPi7HP+Hn4aGc8iJl2zYyVL+tRIdY89U1Zk="}]}},"0.0.7":{"name":"mongoose-auth","description":"User authentication plugin for mongoose node.js orm","version":"0.0.7","homepage":"https://github.com/bnoguchi/mongoose-auth/","repository":{"type":"git","url":"git://github.com/bnoguchi/mongoose-auth.git"},"author":{"name":"Brian Noguchi","email":"brian.noguchi@gmail.com","url":"https://github.com/bnoguchi/"},"main":"./index.js","directories":{"lib":"."},"dependencies":{"bcrypt":">=0.2.0","mongoose":">=1.3.0","everyauth":">=0.1.6","mongoose-types":">=1.0.3"},"engines":{"node":"0.4.x"},"devDependencies":{},"_id":"mongoose-auth@0.0.7","_engineSupported":true,"_npmVersion":"1.0.1rc9","_nodeVersion":"v0.4.7","_defaultsLoaded":true,"dist":{"shasum":"512eba3d4065dada880bc49505516e043baf176e","tarball":"https://registry.npmjs.org/mongoose-auth/-/mongoose-auth-0.0.7.tgz","integrity":"sha512-ffW8QzodMeaRSqHULLcbrRx+W4IlYeS1VpFeSrc1Db4lI+FfrkEbxsRfvTDCUJqOtDM9RXRU+/MfIjgLZoZ+jA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIHfMxoVhPZ4qXro/x45gf/rTnLLcXl8UpirMQR8QNLS4AiEA/Go242N4ep9r4tTEn+Pe840knjh/1fmWcW/KYh1tLS0="}]}},"0.0.9":{"name":"mongoose-auth","description":"User authentication plugin for mongoose node.js orm","version":"0.0.9","homepage":"https://github.com/bnoguchi/mongoose-auth/","repository":{"type":"git","url":"git://github.com/bnoguchi/mongoose-auth.git"},"author":{"name":"Brian Noguchi","email":"brian.noguchi@gmail.com","url":"https://github.com/bnoguchi/"},"main":"./index.js","directories":{"lib":"."},"dependencies":{"bcrypt":">=0.2.0","mongoose":">=1.3.3","everyauth":">=0.2.0","mongoose-types":">=1.0.3"},"devDependencies":{"express":">=2.3.2","jade":">=0.10.6"},"engines":{"node":"0.4.x"},"_id":"mongoose-auth@0.0.9","_engineSupported":true,"_npmVersion":"1.0.3","_nodeVersion":"v0.4.7","_defaultsLoaded":true,"dist":{"shasum":"9466f17ad17a09216fdba2e4d96e8c6d77dfaa34","tarball":"https://registry.npmjs.org/mongoose-auth/-/mongoose-auth-0.0.9.tgz","integrity":"sha512-5IhuYAstn2U/ffvPKNrypqSFlB7t39c7G2nNwS+uJisKDIX+PYv+GgXdR1B/iT2YzeEsG5Fk+tazI63v9TE8xw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCICqgWO4diQtnOTOg1OcN76aF15foC8+J8rFwjVgZLPUbAiEA6MM9451KDVidveMRHThsdoOUCuuGV9lTrZuGetOcVGo="}]},"scripts":{}},"0.0.10":{"name":"mongoose-auth","description":"User authentication plugin for mongoose node.js orm","version":"0.0.10","homepage":"https://github.com/bnoguchi/mongoose-auth/","repository":{"type":"git","url":"git://github.com/bnoguchi/mongoose-auth.git"},"author":{"name":"Brian Noguchi","email":"brian.noguchi@gmail.com","url":"https://github.com/bnoguchi/"},"main":"./index.js","directories":{"lib":"."},"dependencies":{"bcrypt":">=0.2.0","mongoose":">=1.3.7","everyauth":">=0.2.5","mongoose-types":">=1.0.3"},"devDependencies":{"express":">=2.3.2","jade":">=0.12.1"},"engines":{"node":">=0.4.x"},"_id":"mongoose-auth@0.0.10","_engineSupported":true,"_npmVersion":"1.0.9-1","_nodeVersion":"v0.4.8","_defaultsLoaded":true,"dist":{"shasum":"0f39bfff194f1684ca8816477470b057e67b06b2","tarball":"https://registry.npmjs.org/mongoose-auth/-/mongoose-auth-0.0.10.tgz","integrity":"sha512-kOpaNuZ3qH0q0HnbvvWWZOR0IcirQsJIJOFls7SGt8x+eTScX3KenvjeCfsIYG37IEZW1YCfl92YWoBIVTQ6Ag==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIByklWpcjOC7jxNbTtPQGt/s8iy36B8XI4ID9e3LL4tqAiEAvBziJL5y3xMuRxzg5QOlgvSnHNuy0Fb4v6+jHqJf3mk="}]},"scripts":{}},"0.0.11":{"name":"mongoose-auth","description":"User authentication plugin for mongoose node.js orm","version":"0.0.11","homepage":"https://github.com/bnoguchi/mongoose-auth/","repository":{"type":"git","url":"git://github.com/bnoguchi/mongoose-auth.git"},"author":{"name":"Brian Noguchi","email":"brian.noguchi@gmail.com","url":"https://github.com/bnoguchi/"},"main":"./index.js","directories":{"lib":"."},"dependencies":{"bcrypt":">=0.2.0","mongoose":">=1.4.0","everyauth":">=0.2.11","mongoose-types":">=1.0.3"},"devDependencies":{"express":">=2.3.2","jade":">=0.12.1"},"engines":{"node":">=0.4.0"},"_npmJsonOpts":{"file":"/home/briannoguchi/.npm/mongoose-auth/0.0.11/package/package.json","wscript":false,"contributors":false,"serverjs":false},"_id":"mongoose-auth@0.0.11","_engineSupported":true,"_npmVersion":"1.0.18","_nodeVersion":"v0.4.9","_defaultsLoaded":true,"dist":{"shasum":"f55c2888621c758fbb755218899150ccde04869e","tarball":"https://registry.npmjs.org/mongoose-auth/-/mongoose-auth-0.0.11.tgz","integrity":"sha512-IbTlJ/48X5xMqo/JaBpPT6vVUxV1PR63dVo3crOYSuXs2vUGMtMSvUyvgIhiAzM3hIM9XDG4aQ5FTO0KbsvgaA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIHohkt6VCaVAS89rimAE2mJEGMXFcyxW15wrlZyOuSh1AiEAocYTpD0EMXvLWht64C6OqZ1IdfTeryUsvrV6BZr42dM="}]},"scripts":{}},"0.0.12":{"name":"mongoose-auth","description":"User authentication plugin for mongoose node.js orm","version":"0.0.12","homepage":"https://github.com/bnoguchi/mongoose-auth/","repository":{"type":"git","url":"git://github.com/bnoguchi/mongoose-auth.git"},"author":{"name":"Brian Noguchi","email":"brian.noguchi@gmail.com","url":"https://github.com/bnoguchi/"},"main":"./index.js","directories":{"lib":"."},"dependencies":{"bcrypt":">=0.5.0","mongoose":">=2.4.8","everyauth":">=0.2.28","mongoose-types":">=1.0.3"},"devDependencies":{"express":">=2.3.2","jade":">=0.12.1","mocha":">=0.10.1","should":">=0.5.1"},"scripts":{"test":"make"},"engines":{"node":">=0.4.0"},"_npmUser":{"name":"bnoguchi","email":"brian.noguchi@gmail.com"},"_id":"mongoose-auth@0.0.12","_engineSupported":true,"_npmVersion":"1.1.0-beta-4","_nodeVersion":"v0.6.6","_defaultsLoaded":true,"dist":{"shasum":"cbeb140cda42e75f68e386599b1a8aa3dfdb1e35","tarball":"https://registry.npmjs.org/mongoose-auth/-/mongoose-auth-0.0.12.tgz","integrity":"sha512-T70gaqh6hBzE8YTWdU4QpAjd7XHT2ihsx1zIi7jxvUc/2jwbJL4JmBfvDzal45kuIqiiVq7hIHj2iRDYgliNIQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIADQhv90UWq8E0VxyowUoRFys6oJzO5jK0fcjfq8cPAkAiAe9RSmUb00y+F4kb9x15jVWaL4iF0ENdG3oJ5ff8AW4Q=="}]},"readme":"mongoose-auth\n=============\n\nUser authentication plugin for mongoose node.js orm.\n\nmongoose-auth enables you to support authorization in any number of ways\nvia authorization strategies.\n\nAn authorization strategy is how you authorize your user. Currently\nmongoose-auth supports the following authorization strategies:\n\n- `password`\n- `facebook`\n- `twitter`\n- `github`\n- `instagram`\n- `google`\n\nmongoose-auth does 3 things:\n\n1. Schema decoration\n2. (optional) Drop in routing for \n   [connect](https://github.com/senchalabs/connect) apps.\n3. (optional) Dynamic helpers for \n   [express](https://github.com/visionmedia/express) apps.\n\nIt integrates the [everyauth](https://github.com/bnoguchi/everyauth) module\nto help it take care of the routing and helpers. everyauth is a general\npurpose npm module for authentication & authorization that can be used\nindependently of mongoose.\n\n## Schema Decoration\n\nAs you add successive authorization strategies, mongoose-auth at a bare\nminimum augments your schema with typed attributes corresponding to parameters\nrelated to your chosen authorization strategies. For example, if facebook is \none of your authorization strategies, then it will add attributes to your \nUser Schema such as 'fb.id' and 'fb.email'.\n\nTo decorate your schema:\n\n```javascript\n    var mongoose = require('mongoose')\n      , Schema = mongoose.Schema\n      , mongooseAuth = require('mongoose-auth');\n    \n    var UserSchema = new Schema({});\n    UserSchema.plugin(mongooseAuth, {\n      facebook: true\n    });\n```\n\n## Beyond Schema Decoration: Routing\n\nApplications require more than just User Schema augmentation in order\nto implement a complete authorization strategy. Applications also need\nroutes exposing the one or more steps involved for a given authorization\nstrategy. Moreover, applications each handle in their own unique way how\nthey want to respond to successful or failed logins (in addition to logout\nhandling). If you are not using a \n[connect](https://github.com/senchalabs/connect), then you will have to\nset all of this up yourself. In this case, mongoose-auth *only* provides\nyou with Schema decoration.\n\nBut, if you are building your app on top of\n[connect](https://github.com/senchalabs/connect), then mongoose-auth\nprovides drop in solutions for you. Here is how you can get access\nto the routing that mongoose-auth provides. Not the \"STEP X: ...\"\ncomments:\n\n```javascript\n    var mongoose = require('mongoose')\n      , Schema = mongoose.Schema\n      , mongooseAuth = require('mongoose-auth');\n    \n    var UserSchema = new Schema({})\n      , User;\n   \n    // STEP 1: Schema Decoration and Configuration for the Routing\n    UserSchema.plugin(mongooseAuth, {\n        // Here, we attach your User model to every module\n        everymodule: {\n          everyauth: {\n              User: function () {\n                return User;\n              }\n          }\n        }\n        \n      , facebook: {\n          everyauth: {\n              myHostname: 'http://localhost:3000'\n            , appId: 'YOUR APP ID HERE'\n            , appSecret: 'YOUR APP SECRET HERE'\n            , redirectPath: '/'\n          }\n        }\n    });\n   \n    mongoose.model('User', UserSchema);\n\n    mongoose.connect('mongodb://localhost/example');\n\n    User = mongoose.model('User');\n\n    var app = express.createServer(\n        express.bodyParser()\n      , express.static(__dirname + \"/public\")\n      , express.cookieParser()\n      , express.session({ secret: 'esoognom'})\n      \n        // STEP 2: Add in the Routing\n      , mongooseAuth.middleware()\n\n        // IMPORTANT!!!!!!! Do not add app.router, to your middleware chain \n        // explicitly, or you will run into problems accessing `req.user`\n        // i.e., do not use app.use(app.router). Let express do this for you\n        // automatically for you upon your first app.get or app.post.\n    );\n   \n    // STEP 3: Add in Dynamic View Helpers (only if you are using express)\n    mongooseAuth.helpExpress(app);\n\n    app.listen(3000);\n```\n\n## View Helpers and Convenience Methods & Getters\n\nIn \"Step 3\" of the last code sample, we are adding dynamic view helpers, for if\nyou are using the [Express](https://github.com/visionmedia/express) web framework.\nThis automically gives you access to a convenient `everyauth` local variable from\nyour view, so you do not have to pass `req` as a local to your view:\n\n- `everyauth.loggedIn` - a Boolean getter that tells you if the request is by a logged in user\n- `everyauth.user` - the mongoose User document associated with the session\n- `everyauth.facebook` - The is equivalent to what is stored at `req.session.auth.facebook`, \n  so you can do things like ...\n- `everyauth.facebook.user` - returns the user json provided from the OAuth provider.\n- `everyauth.facebook.accessToken` - returns the access_token provided from the OAuth provider\n  for authorized API calls on behalf of the user.\n- And you also get this pattern for other modules - e.g., `everyauth.twitter.user`, \n  `everyauth.github.user`, etc.\n\nYou also get access to the view helper\n\n- `user` - the same as `everyauth.user` above\n\nAs an example of how you would use these, consider the following `./views/user.jade` jade template:\n\n    .user-id\n      .label User Id\n      .value #{user.id}\n    .facebook-id\n      .label User Facebook Id\n      .value #{everyauth.facebook.user.id}\n\nThe \"STEP 2: Add in the Routing\" step in the last code sample also provides convenience methods on the\n`ServerRequest` instance `req`. From any scope that has access to `req`, you get the following\nconvenience getter and method:\n\n- `req.loggedIn` - a Boolean getter that tells you if the request is by a logged in user\n- `req.user`     - the mongoose User document associated with the session\n- `req.logout()` - clears the sesion of your auth data\n\n## Using Multiple Authorization Strategies at Once\n\nYou can also use multiple authorization strategies in the same application.\nHere is an example, using 5 authorization strategies:\n\n```javascript\n    // A configuration file for holding all of your\n    // 3rd party OAuth credentials\n    var conf = require('./conf');\n    UserSchema.plugin(mongooseAuth, {\n        // Here, we attach your User model to every module\n        everymodule: {\n          everyauth: {\n              User: function () {\n                return User;\n              }\n          }\n        }\n      , facebook: {\n          everyauth: {\n              myHostname: 'http://localhost:3000'\n            , appId: conf.fb.appId\n            , appSecret: conf.fb.appSecret\n            , redirectPath: '/'\n          }\n        }\n      , twitter: {\n          everyauth: {\n              myHostname: 'http://localhost:3000'\n            , consumerKey: conf.twit.consumerKey\n            , consumerSecret: conf.twit.consumerSecret\n            , redirectPath: '/'\n          }\n        }\n      , password: {\n            everyauth: {\n                getLoginPath: '/login'\n              , postLoginPath: '/login'\n              , loginView: 'login.jade'\n              , getRegisterPath: '/register'\n              , postRegisterPath: '/register'\n              , registerView: 'register.jade'\n              , loginSuccessRedirect: '/'\n              , registerSuccessRedirect: '/'\n            }\n        }\n      , github: {\n          everyauth: {\n              myHostname: 'http://localhost:3000'\n            , appId: conf.github.appId\n            , appSecret: conf.github.appSecret\n            , redirectPath: '/'\n          }\n        }\n      , instagram: {\n          everyauth: {\n              myHostname: 'http://localhost:3000'\n            , appId: conf.instagram.clientId\n            , appSecret: conf.instagram.clientSecret\n            , redirectPath: '/'\n          }\n        }\n    });\n```\n\n## Example\n\nThere is an example app located in [./example](https://github.com/bnoguchi/mongoose-auth/tree/master/example).\nTo run it:\n\n    $ cd example\n    $ node server.js\n\nThen navigate to [http://localhost:3000/](http://localhost:3000)\n\n## Recipe 1: Linking Multiple Account Logins Together\n\nA common recipe is allowing a user to login via multiple accounts *and* to link those accounts under one user\ndocument.\n\nThis can be done in the following way:\n\nThe real magic lies with https://github.com/bnoguchi/everyauth/, and it should be more obvious once \nI document everyauth more and document mongoose-auth's relationship to everyauth.\n\nIn `everyauth`'s design, every auth module is defined as a set of steps, which are exposed in such a way for \nyou to over-ride. The step that is of particular interest for this scenario is the `findOrCreateUser` step \nrequired by every `everyauth` module.  `mongoose-auth` defines a default version of this `findOrCreateUser` \nstep for each `everyauth` auth module it supports (You can find these default definitions in \n\"lib/modules/#{moduleName}/everyauth.js\" -- e.g., see \n[.lib/modules/facebook/everyauth.js](https://github.com/bnoguchi/mongoose-auth/tree/master/lib/modules/facebook/everyauth.js)).\n\nSo for example, this is how you would over-ride the default `findOrCreateUser` step for the \nfacebook module if you are using both the facebook and password module:\n\n```javascript\nUserSchema.plugin(mongooseAuth, {\n  facebook: {\n    everyauth: {\n        myHostname: ...\n      , ...\n      , findOrCreateUser: function (session, accessTok, accessTokExtra, fbUser) {\n          var promise = this.Promise()\n              , User = this.User()();\n          User.findById(session.auth.userId, function (err, user) {\n            if (err) return promise.fail(err);\n            if (!user) {\n              User.where('password.login', fbUser.email).findOne( function (err, user) {\n                if (err) return promise.fail(err);\n                if (!user) {\n                  User.createWithFB(fbUser, accessTok, accessTokExtra.expires, function (err, createdUser) {\n                    if (err) return promise.fail(err);\n                    return promise.fulfill(createdUser);\n                  });\n                } else {\n                  assignFbDataToUser(user, accessTok, accessTokExtra, fbUser);\n                  user.save( function (err, user) {\n                    if (err) return promise.fail(err);\n                    promise.fulfill(user);\n                  });\n                }\n              });\n            } else {\n              assignFbDataToUser(user, accessTok, accessTokExtra, fbUser);\n              \n              // Save the new data to the user doc in the db\n              user.save( function (err, user) {\n                if (err) return promise.fail(err);\n                promise.fuilfill(user);\n              });\n            }\n          });\n        });\n        return promise; // Make sure to return the promise that promises the user\n      }\n  }\n});\n\n// Assign all properties - see lib/modules/facebook/schema.js for details\nfunction assignFbDataToUser (user, accessTok, accessTokExtra, fbUser) {\n  user.fb.accessToken = accessTok;\n  user.fb.expires = accessTokExtra.expires;\n  user.fb.id = fbUser.id;\n  user.fb.name.first = fbUser.first_name;\n  // etc. more assigning...\n}\n```\n\nAs this is a common recipe, I plan on adding support for this into `everyauth` and `mongoose-auth`, so it's more drop-in, and developers do not have to add this custom code themselves. The intent is for common things like this to be invisible to the developer, so it just *works* *like* *magic*. So, in the near future, you won't have to over-ride the findOrCreateUser step every time you want this feature. This will be coming soon.\n\n## Recipe 2: Configuring Email or Phone to be your Login for the Password Module\n\nBy default, `everyauth` and therefore `mongoose-auth` use the attribute `login` as the default attribute used for logging in\nwith the password module.\n\nHowever, the need can arise to use a different attribute (such as email) that implies a different schema (use `email: String` instead of `login: String`)\nin addition to different validation assumptions (email validations are more strict that login handle validations).\n\nLuckily, `mongoose-auth` provide support for this out of the box. All you need to do is (look for the line labeled \"THIS NEXT LINE IS THE ONLY ADDITION\"):\n\n```javascript\nUserSchema.plugin(mongooseAuth, {\n    // Here, we attach your User model to every module\n    everymodule: {\n      everyauth: {\n          User: function () {\n            return User;\n          }\n      }\n    }\n  , password: {\n        // THIS NEXT LINE IS THE ONLY ADDITION\n        loginWith: 'email' // Or loginWith: 'phone'\n\n      , everyauth: {\n            getLoginPath: '/login'\n          , postLoginPath: '/login'\n          , loginView: 'login.jade'\n          , getRegisterPath: '/register'\n          , postRegisterPath: '/register'\n          , registerView: 'register.jade'\n          , loginSuccessRedirect: '/'\n          , registerSuccessRedirect: '/'\n        }\n    }\n});\n```\n\nAutomatically, `mongoose-auth` will use an `email` String attribute in your User schema\ninstead of the default `login` String attribute. Moreover, it will automatically add in\nvalidation checks to make sure that the email is valid before registering a user through\nthe registration process of the password module.\n\n## Recipe 3: Extra password registration data besides login + password\n\nSometimes your registration will ask for more information from the user besides the login and password.\n\nFor this particular scenario, you can configure `extraParams`.\n\n```javascript\nUserSchema.plugin(mongooseAuth, {\n    // Here, we attach your User model to every module\n    everymodule: {\n      everyauth: {\n          User: function () {\n            return User;\n          }\n      }\n    }\n  , password: {\n        extraParams: {\n            phone: String\n          , name: {\n                first: String\n              , last: String\n            }\n        }\n\n      , everyauth: {\n            getLoginPath: '/login'\n          , postLoginPath: '/login'\n          , loginView: 'login.jade'\n          , getRegisterPath: '/register'\n          , postRegisterPath: '/register'\n          , registerView: 'register.jade'\n          , loginSuccessRedirect: '/'\n          , registerSuccessRedirect: '/'\n        }\n    }\n});\n```\n\nWhat this effectively does is:\n\n1. Adds `phone`, `name.first`, and `name.last` as attributes to your `UserSchema`.\n2. Automatically extracts the registration parameters after a visitor submits the registration\n   form and saves them to a new `User` document.\n   The registration form `<input>` `name`s should be, e.g., in the example above: 'phone', \n   'name[first]', and 'name[last]'.\n\nPlease see [./example/server.js](https://github.com/bnoguchi/mongoose-auth/tree/master/example/server.js#L45)\nfor a live example.\n\n## Recipe 4: Adding more attributes to your schema\n\nThis one ha come up enough that it is here as a recipe, even though it is not specific to `mongoose-auth`. Suppose\nyou want to add a special attribute such as `roles: [String]` to your UserSchema. This is something that you can do\nusing just `mongoose`\n\n```javascript\nvar UserSchema = new mongoose.Schema({\n    roles: [String]\n  , // other custom attributes\n});\n\nUserSchema.plugin(mongooseAuth, {\n  // mongooseAuth *adds* other attributes to your UserSchema\n  // depending on the auth modules you choose.\n});\n```\n\n## Recipe 5: Customizing how you do password login authentication\n\nCurrently, `mongoose-auth` does password authentication by login and password. Suppose you also want to authenticate\nby checking against an additional parameter, like `active`, which is a Boolean attribute on your UserSchema that\nindicates whether this user has been activated or not. Then you can modify the `authenticate` everyauth step in the\nfollowing way:\n\n```javascript\nvar UserSchema = new Schema({\n  active: Boolean\n}), User;\nUserSchema.plugin(mongooseAuth, {\n    everymodule: {\n      everyauth: {\n          User: function () {\n            return User;\n          }\n      }\n    }\n  , password: {\n        loginWith: 'email' \n      , everyauth: {\n            getLoginPath: '/login'\n          , postLoginPath: '/login'\n          , loginView: 'login.jade'\n          , getRegisterPath: '/register'\n          , postRegisterPath: '/register'\n          , registerView: 'register.jade'\n          , loginSuccessRedirect: '/'\n          , registerSuccessRedirect: '/'\n   \n            // WHAT YOU ADD IS THE FOLLOWING:\n            // The logic is adapted from the default authenticate\n            // implementation in lib/modules/password/everyauth.js\n          , authenticate: function (login, password) {\n              var promise\n                , errors = []; \n              if (!login) errors.push('Missing login.');\n              if (!password) errors.push('Missing password.');\n              if (errors.length) return errors;\n\n              promise = this.Promise();\n              this.User()().authenticate(login, password, function (err, user) {\n                if (err) {\n                  errors.push(err.message || err);\n                  return promise.fulfill(errors);\n                }   \n                if (!user) {\n                  errors.push('Failed login.');\n                  return promise.fulfill(errors);\n                }\n                \n                // The following block is the new code\n                if (!user.active) {\n                  errors.push('You are not yet activated.');\n                  return promise.fulfill(errors);\n                }\n                \n                promise.fulfill(user);\n              });\n              return promise;\n            }\n        }\n    }\n});\nmongoose.model('User', UserSchema);\n\nUser = mongoose.model('User');\n```\n\n### License\nMIT License\n\n---\n### Author\nBrian Noguchi\n","maintainers":[{"name":"bnoguchi","email":"brian.noguchi@gmail.com"}]}},"maintainers":[{"name":"bnoguchi","email":"brian.noguchi@gmail.com"}],"time":{"modified":"2022-06-20T06:52:00.224Z","created":"2011-04-06T02:28:46.716Z","0.0.1":"2011-04-06T02:28:47.164Z","0.0.2":"2011-04-06T03:13:54.893Z","0.0.3":"2011-04-07T01:41:14.094Z","0.0.4":"2011-04-12T18:29:29.919Z","0.0.5":"2011-04-13T23:08:18.876Z","0.0.6":"2011-04-26T20:22:28.181Z","0.0.7":"2011-04-29T01:50:17.748Z","0.0.9":"2011-05-03T17:20:10.241Z","0.0.10":"2011-06-04T21:55:24.040Z","0.0.11":"2011-06-20T21:54:55.875Z","0.0.12":"2012-02-09T23:18:09.740Z"},"author":{"name":"Brian Noguchi","email":"brian.noguchi@gmail.com","url":"https://github.com/bnoguchi/"},"repository":{"type":"git","url":"git://github.com/bnoguchi/mongoose-auth.git"},"users":{"troygoode":true,"m42am":true,"hoitmort":true}}