{"id":18926782,"url":"https://github.com/ladjs/passport-otp-strategy","last_synced_at":"2026-03-15T08:30:17.279Z","repository":{"id":57126136,"uuid":"498094047","full_name":"ladjs/passport-otp-strategy","owner":"ladjs","description":"Fork of \"passport-otp-strategy\" since it is no longer maintained","archived":false,"fork":false,"pushed_at":"2022-05-30T21:57:45.000Z","size":172,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-31T23:04:14.649Z","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/ladjs.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}},"created_at":"2022-05-30T20:55:24.000Z","updated_at":"2022-05-30T21:46:35.000Z","dependencies_parsed_at":"2022-08-31T19:03:49.844Z","dependency_job_id":null,"html_url":"https://github.com/ladjs/passport-otp-strategy","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ladjs%2Fpassport-otp-strategy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ladjs%2Fpassport-otp-strategy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ladjs%2Fpassport-otp-strategy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ladjs%2Fpassport-otp-strategy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ladjs","download_url":"https://codeload.github.com/ladjs/passport-otp-strategy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239922686,"owners_count":19719002,"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":"2024-11-08T11:17:10.119Z","updated_at":"2026-03-15T08:30:17.231Z","avatar_url":"https://github.com/ladjs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @ladjs/passport-otp-strategy\n\n[![npm](https://img.shields.io/npm/v/@ladjs/passport-otp-strategy.svg)](https://www.npmjs.com/package/@ladjs/passport-otp-strategy)\n[![Build Status](https://secure.travis-ci.org/ladjs/passport-otp-strategy.png)](http://travis-ci.org/ladjs/passport-otp-strategy)\n\n\n## Table of Contents\n\n* [Foreword](#foreword)\n* [Install](#install)\n* [Usage](#usage)\n* [Examples](#examples)\n* [Tests](#tests)\n* [Contributors](#contributors)\n* [License](#license)\n\n\n## Foreword\n\nThis is a fork of [passport-otp](https://github.com/ejhayes/passport-otp), which is a fork itself of the [Passport-TOTP](https://github.com/jaredhanson/passport-totp) library and uses `otplib` instead of `notp`.\n\n[Passport](http://passportjs.org/) strategy for two-factor authentication using\na [TOTP](http://tools.ietf.org/html/rfc6238) value.\n\nThis module lets you authenticate using a TOTP value in your Node.js\napplications.  By plugging into Passport, TOTP two-factor authentication can be\neasily and unobtrusively integrated into any application or framework that\nsupports [Connect](http://www.senchalabs.org/connect/)-style middleware,\nincluding [Express](http://expressjs.com/).  TOTP values can be generated by\nhardware devices or software applications, including [Google Authenticator](https://code.google.com/p/google-authenticator/)\nand [Authy](https://authy.com/).\n\nNote that in contrast to most Passport strategies, TOTP authentication requires\nthat a user already be authenticated using an initial factor.  Requirements\nregarding when to require a second factor are a matter of application-level\npolicy, and outside the scope of both Passport and this strategy.\n\n\n## Install\n\n```sh\nnpm install @ladjs/passport-otp-strategy\n```\n\n\n## Usage\n\n#### Configure Strategy\n\nThe TOTP authentication strategy authenticates a user using a TOTP value\ngenerated by a hardware device or software application (known as a token).  The\nstrategy requires a `setup` callback.\n\nThe `setup` callback accepts a previously authenticated `user` and calls `done`\nproviding a `key` used to verify the token value.  Authentication\nfails if the value is not verified.\n\n```js\npassport.use(new OtpStrategy(\n  {\n    codeField: 'code',\n    authenticator: {}\n  }\n  function(user, done) {\n    TotpKey.findOne({ userId: user.id }, function (err, key) {\n      if (err) { return done(err); }\n      return done(null, key.key);\n    });\n  }\n));\n```\n\nYou can find a full listing of `authenticator` options [here](https://www.npmjs.com/package/otplib#available-options). Note that the `crypto` library will be used by default. If you want to change that, you can specify it in `authenticator.crypto` (more on that [here](https://www.npmjs.com/package/otplib#using-specific-otp-implementations)).\n\n#### Authenticate Requests\n\nUse `passport.authenticate()`, specifying the `'otp'` strategy, to authenticate\nrequests.\n\nFor example, as route middleware in an [Express](http://expressjs.com/)\napplication:\n\n```js\napp.post(\n  '/verify-otp',\n  passport.authenticate('otp', { failureRedirect: '/verify-otp' }),\n  function(req, res) {\n    req.session.authFactors = [ 'otp' ];\n    res.redirect('/');\n  }\n);\n```\n\n\n## Examples\n\nFor a complete, working example, refer [Lad](https://lad.js.org) source code.\n\n\n## Tests\n\n```sh\nnpm install\nnpm run test\n```\n\n\n## Contributors\n\n| Name             | Website                          |\n| ---------------- | -------------------------------- |\n| **Eric Hayes**   | \u003chttps://github.com/ejhayes\u003e     |\n| **Jared Hanson** | \u003chttps://github.com/jaredhanson\u003e |\n\n\n## License\n\n[MIT](LICENSE) © [Eric Hayes](https://github.com/ejhayes)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fladjs%2Fpassport-otp-strategy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fladjs%2Fpassport-otp-strategy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fladjs%2Fpassport-otp-strategy/lists"}