{"id":13998581,"url":"https://github.com/jeremyscalpello/node-2fa","last_synced_at":"2025-04-12T14:59:01.672Z","repository":{"id":39738070,"uuid":"45340789","full_name":"jeremyscalpello/node-2fa","owner":"jeremyscalpello","description":"Easy 2-Factor Integration For Node.JS","archived":false,"fork":false,"pushed_at":"2023-01-06T18:09:04.000Z","size":653,"stargazers_count":209,"open_issues_count":17,"forks_count":25,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-05-16T02:47:34.018Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jeremyscalpello.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":"2015-11-01T13:09:03.000Z","updated_at":"2024-04-22T08:26:30.000Z","dependencies_parsed_at":"2023-02-06T07:45:36.032Z","dependency_job_id":null,"html_url":"https://github.com/jeremyscalpello/node-2fa","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeremyscalpello%2Fnode-2fa","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeremyscalpello%2Fnode-2fa/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeremyscalpello%2Fnode-2fa/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeremyscalpello%2Fnode-2fa/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jeremyscalpello","download_url":"https://codeload.github.com/jeremyscalpello/node-2fa/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248586249,"owners_count":21128997,"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-08-09T19:01:47.809Z","updated_at":"2025-04-12T14:59:01.654Z","avatar_url":"https://github.com/jeremyscalpello.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# node-2fa\n\nEasy 2-Factor Integration For Node.js\n\nThere are a number of applications which support 2-Factor Authentication, namely\n\n- Authy [iPhone](https://itunes.apple.com/us/app/authy/id494168017?mt=8) | [Android](https://play.google.com/store/apps/details?id=com.authy.authy\u0026hl=en) | [Chrome](https://chrome.google.com/webstore/detail/authy/gaedmjdfmmahhbjefcbgaolhhanlaolb?hl=en) | [Linux](https://www.authy.com/personal/) | [OS X](https://www.authy.com/personal/) | [BlackBerry](https://appworld.blackberry.com/webstore/content/38831914/?countrycode=US\u0026lang=en)\n- Google Authenticator [iPhone](https://itunes.apple.com/us/app/google-authenticator/id388497605?mt=8) | [Android](https://play.google.com/store/apps/details?id=com.google.android.apps.authenticator2\u0026hl=en)\n- Microsoft Authenticator [Windows Phone](https://www.microsoft.com/en-us/store/apps/authenticator/9wzdncrfj3rj) | [Android](https://play.google.com/store/apps/details?id=com.microsoft.msa.authenticator)\n\nThis module uses [`notp`](https://github.com/guyht/notp) which implements `TOTP` [(RFC 6238)](https://www.ietf.org/rfc/rfc6238.txt)\n(the _Authenticator_ standard), which is based on `HOTP` [(RFC 4226)](https://www.ietf.org/rfc/rfc4226.txt)\nto provide codes that are exactly compatible with all other _Authenticator_ apps and services that use them.\n\nUsage\n=====\n\n```bash\nnpm install node-2fa --save\n```\n\n```javascript\nconst twofactor = require(\"node-2fa\");\n\nconst newSecret = twofactor.generateSecret({ name: \"My Awesome App\", account: \"johndoe\" });\n/*\n{ secret: 'XDQXYCP5AC6FA32FQXDGJSPBIDYNKK5W',\n  uri: 'otpauth://totp/My%20Awesome%20App:johndoe?secret=XDQXYCP5AC6FA32FQXDGJSPBIDYNKK5W\u0026issuer=My%20Awesome%20App',\n  qr: 'https://chart.googleapis.com/chart?chs=166x166\u0026chld=L|0\u0026cht=qr\u0026chl=otpauth://totp/My%20Awesome%20App:johndoe%3Fsecret=XDQXYCP5AC6FA32FQXDGJSPBIDYNKK5W%26issuer=My%20Awesome%20App'\n}\n*/\n\nconst newToken = twofactor.generateToken(\"XDQXYCP5AC6FA32FQXDGJSPBIDYNKK5W\");\n// =\u003e { token: '630618' }\n\ntwofactor.verifyToken(\"XDQXYCP5AC6FA32FQXDGJSPBIDYNKK5W\", \"630618\");\n// =\u003e { delta: 0 }\n\ntwofactor.verifyToken(\"XDQXYCP5AC6FA32FQXDGJSPBIDYNKK5W\", \"00\");\n// =\u003e null\n```\n\n## API\n\n### generateSecret(options)\n\nreturns an object containing a 32-character secret (keep user specific, store in DB), a uri (if you want to make your own QR / barcode) and a direct link to a QR code served via HTTPS by the Google Chart API\n\noptions is an object containing `name` which is the name of your app that will show up when the user scans the QR code and `account` which can be the username and will also show up in the user's app. Both parameters are optional\n\n### generateToken(secret)\n\nreturns an object containing a 6-character token\n\n### verifyToken(secret, token, window)\n\nchecks if a time-based token matches a token from secret key within a +/- _window_ (default: 4) minute window\n\nreturns either `null` if the token does not match, or an object containing delta key, which is an integer of how for behind / forward the code time sync is in terms of how many new codes have been generated since entry\n\nex.\n`{delta: -1}` means that the client entered the key too late (a newer key was meant to be used).\n`{delta: 1}` means the client entered the key too early (an older key was meant to be used).\n`{delta: 0}` means the client was within the time frame of the current key.\n\n## _n_-Minute Window\n\nThe window is set to 4 by default. Each token is valid for a total of _n_ minutes to account for time drift.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjeremyscalpello%2Fnode-2fa","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjeremyscalpello%2Fnode-2fa","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjeremyscalpello%2Fnode-2fa/lists"}