{"bugs":{"url":"http://github.com/jaredhanson/connect-ensure-login/issues"},"dist":{"shasum":"174dcc51243b9eac23f8d98215aeb6694e2e8a12","tarball":"https://registry.npmjs.org/connect-ensure-login/-/connect-ensure-login-0.1.1.tgz","integrity":"sha512-u0LGY/YXgkqdD4uVz8Gkri0adby5SBPYIFQvIa4FjBIaZUN0yuZPVHsjAA2bUiprGyjh8NlqxPUcIzzfTiXhQQ==","signatures":[{"sig":"MEUCIDLQs1lX9QXtp0x2Nsg+mUGS+sZMpZVVp3UQdVjwi0kyAiEAsJveD5MWubWk7EQPGCRvtyzvyJTy3orf/kQypta5tuE=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"./lib","name":"connect-ensure-login","author":{"url":"http://www.jaredhanson.net/","name":"Jared Hanson","email":"jaredhanson@gmail.com"},"readme":"# connect-ensure-login\n\nThis middleware ensures that a user is logged in.  If a request is received that\nis unauthenticated, the request will be redirected to a login page.  The URL\nwill be saved in the session, so the user can be conveniently returned to the\npage that was originally requested.\n\n## Install\n\n    $ npm install connect-ensure-login\n\n## Usage\n\n#### Ensure Authentication\n\nIn this example, an application has a settings page where preferences can be\nconfigured.  A user must be logged in before accessing this page.\n\n    app.get('/settings',\n      ensureLoggedIn('/login'),\n      function(req, res) {\n        res.render('settings', { user: req.user });\n      });\n      \nIf a user is not logged in when attempting to access this page, the request will\nbe redirected to `/login` and the original request URL (`/settings`) will be\nsaved to the session at `req.session.returnTo`.\n\n#### Log In and Return To\n\nThis middleware integrates seamlessly with [Passport](http://passportjs.org/).\nSimply mount Passport's `authenticate()` middleware at the login route.\n\n    app.get('/login', function(req, res) {\n      res.render('login');\n    });\n\n    app.post('/login', passport.authenticate('local', { successReturnToOrRedirect: '/', failureRedirect: '/login' }));\n    \nUpon log in, Passport will notice the `returnTo` URL saved in the session and\nredirect the user back to `/settings`.\n\n#### Step By Step\n\nIf the user is not logged in, the sequence of requests and responses that take\nplace during this process can be confusing.  Here is a step-by-step overview of\nwhat happens:\n\n1. User navigates to `GET /settings`\n    - Middleware sets `session.returnTo` to `/settings`\n    - Middleware redirects to `/login`\n2. User's browser follows redirect to `GET /login`\n    - Application renders a login form (or, alternatively, offers SSO)\n3. User submits credentials to `POST /login`\n    - Application verifies credentials\n    - Passport reads `session.returnTo` and redirects to `/settings`\n4. User's browser follows redirect to `GET /settings`\n    - Now authenticated, application renders settings page\n\n## Tests\n\n    $ npm install --dev\n    $ make test\n\n[![Build Status](https://secure.travis-ci.org/jaredhanson/connect-ensure-login.png)](http://travis-ci.org/jaredhanson/connect-ensure-login)\n\n## Credits\n\n  - [Jared Hanson](http://github.com/jaredhanson)\n\n## License\n\n[The MIT License](http://opensource.org/licenses/MIT)\n\nCopyright (c) 2012-2013 Jared Hanson <[http://jaredhanson.net/](http://jaredhanson.net/)>\n","engines":{"node":">= 0.4.0"},"scripts":{"test":"NODE_PATH=lib node_modules/.bin/vows test/*-test.js"},"_npmUser":{"name":"jaredhanson","email":"jaredhanson@gmail.com"},"keywords":["connect","express","auth","authn","authentication","login","session","passport"],"licenses":[{"url":"http://www.opensource.org/licenses/MIT","type":"MIT"}],"repository":{"url":"git://github.com/jaredhanson/connect-ensure-login.git","type":"git"},"_npmVersion":"1.1.62","description":"Login session ensuring middleware for Connect.","maintainers":[{"name":"jaredhanson","email":"jaredhanson@gmail.com"}],"dependencies":{},"devDependencies":{"vows":"0.6.x"},"_id":"connect-ensure-login@0.1.1","version":"0.1.1"}