{"id":28076744,"url":"https://github.com/jaredhanson/passport-remember-me","last_synced_at":"2025-05-13T01:49:31.075Z","repository":{"id":8470935,"uuid":"10070649","full_name":"jaredhanson/passport-remember-me","owner":"jaredhanson","description":"Remember Me cookie authentication strategy for Passport and Node.js","archived":false,"fork":false,"pushed_at":"2023-10-06T02:28:00.000Z","size":215,"stargazers_count":218,"open_issues_count":24,"forks_count":103,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-05-13T01:49:25.722Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jaredhanson.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2013-05-15T03:58:57.000Z","updated_at":"2025-02-28T03:02:28.000Z","dependencies_parsed_at":"2022-08-07T04:16:35.256Z","dependency_job_id":"291c321b-7531-4444-a29d-98a2732560b3","html_url":"https://github.com/jaredhanson/passport-remember-me","commit_stats":{"total_commits":9,"total_committers":1,"mean_commits":9.0,"dds":0.0,"last_synced_commit":"255d5506a1fcef57b13de31e742c67a580899819"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaredhanson%2Fpassport-remember-me","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaredhanson%2Fpassport-remember-me/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaredhanson%2Fpassport-remember-me/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaredhanson%2Fpassport-remember-me/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jaredhanson","download_url":"https://codeload.github.com/jaredhanson/passport-remember-me/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253856614,"owners_count":21974576,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-05-13T01:49:30.548Z","updated_at":"2025-05-13T01:49:31.062Z","avatar_url":"https://github.com/jaredhanson.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Passport-Remember Me\n\n[Passport](http://passportjs.org/) strategy for authenticating based on a\nremember me cookie.\n\nThis module lets you authenticate using a remember me cookie (aka persistent\nlogin) in your Node.js applications.  By plugging into Passport, remember me\nauthentication can be easily and unobtrusively integrated into any application\nor framework that supports [Connect](http://www.senchalabs.org/connect/)-style\nmiddleware, including [Express](http://expressjs.com/).\n\n## Install\n\n    $ npm install passport-remember-me\n\n## Usage\n\n#### Configure Strategy\n\nThe remember me authentication strategy authenticates users using a token stored\nin a remember me cookie.  The strategy requires a `verify` callback, which\nconsumes the token and calls `done` providing a user.\n\nThe strategy also requires an `issue` callback, which issues a new token.  For\nsecurity reasons, remember me tokens should be invalidated after being used.\nThe `issue` callback supplies a new token that will be stored in the cookie for\nnext use.\n\n    passport.use(new RememberMeStrategy(\n      function(token, done) {\n        Token.consume(token, function (err, user) {\n          if (err) { return done(err); }\n          if (!user) { return done(null, false); }\n          return done(null, user);\n        });\n      },\n      function(user, done) {\n        var token = utils.generateToken(64);\n        Token.save(token, { userId: user.id }, function(err) {\n          if (err) { return done(err); }\n          return done(null, token);\n        });\n      }\n    ));\n\n#### Authenticate Requests\n\nUse `passport.authenticate()`, specifying the `'remember-me'` strategy, to\nauthenticate requests.\n\nThis is typically used in an application's middleware stack, to log the user\nback in the next time they visit any page on your site.  For example:\n\n    app.configure(function() {\n      app.use(express.cookieParser());\n      app.use(express.bodyParser());\n      app.use(express.session({ secret: 'keyboard cat' }));\n      app.use(passport.initialize());\n      app.use(passport.session());\n      app.use(passport.authenticate('remember-me'));\n      app.use(app.router);\n    });\n    \nNote that `passport.session()` should be mounted *above* `remember-me`\nauthentication, so that tokens aren't exchanged for currently active login\nsessions.\n\n#### Setting the Remember Me Cookie\n\nIf the user enables \"remember me\" mode, an initial cookie should be set when\nthey login.\n\n    app.post('/login', \n      passport.authenticate('local', { failureRedirect: '/login', failureFlash: true }),\n      function(req, res, next) {\n        // issue a remember me cookie if the option was checked\n        if (!req.body.remember_me) { return next(); }\n    \n        var token = utils.generateToken(64);\n        Token.save(token, { userId: req.user.id }, function(err) {\n          if (err) { return done(err); }\n          res.cookie('remember_me', token, { path: '/', httpOnly: true, maxAge: 604800000 }); // 7 days\n          return next();\n        });\n      },\n      function(req, res) {\n        res.redirect('/');\n      });\n\n#### Security Considerations\n\nIf not managed correctly, using a \"remember me\" cookie for automatic\nauthentication increases a service's exposure to potential security threats.\nThere are a number of techniques to reduce and mitigate these threats, and it\nis a matter of application-level policy to asses the level of risk and implement\nappropriate counter measures.\n\nThe following list is recommended reading for understanding these risks:\n\n- [The definitive guide to forms based website authentication](http://stackoverflow.com/questions/549/the-definitive-guide-to-forms-based-website-authentication)\n- [Persistent Login Cookie Best Practice](http://fishbowl.pastiche.org/2004/01/19/persistent_login_cookie_best_practice/)\n- [Improved Persistent Login Cookie Best Practice](http://jaspan.com/improved_persistent_login_cookie_best_practice) [(archive)](http://web.archive.org/web/20130214051957/http://jaspan.com/improved_persistent_login_cookie_best_practice)\n\n## Examples\n\nFor a complete, working example, refer to the [login example](https://github.com/jaredhanson/passport-remember-me/tree/master/examples/login).\n\n## Tests\n\n    $ npm install\n    $ make test\n\n[![Build Status](https://secure.travis-ci.org/jaredhanson/passport-remember-me.png)](http://travis-ci.org/jaredhanson/passport-remember-me)\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) 2013 Jared Hanson \u003c[http://jaredhanson.net/](http://jaredhanson.net/)\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaredhanson%2Fpassport-remember-me","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjaredhanson%2Fpassport-remember-me","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaredhanson%2Fpassport-remember-me/lists"}