{"id":15069856,"url":"https://github.com/duosecurity/duo_universal_nodejs","last_synced_at":"2025-04-10T02:20:30.483Z","repository":{"id":38219306,"uuid":"446546642","full_name":"duosecurity/duo_universal_nodejs","owner":"duosecurity","description":"Duo OIDC-based two-factor authentication for NodeJS web applications","archived":false,"fork":false,"pushed_at":"2024-10-17T13:59:16.000Z","size":628,"stargazers_count":16,"open_issues_count":3,"forks_count":15,"subscribers_count":21,"default_branch":"main","last_synced_at":"2025-04-03T01:12:14.680Z","etag":null,"topics":["duo","mfa","nodejs"],"latest_commit_sha":null,"homepage":"https://duo.com/docs/duoweb","language":"TypeScript","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/duosecurity.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":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-01-10T18:57:34.000Z","updated_at":"2025-03-29T22:24:13.000Z","dependencies_parsed_at":"2024-03-18T16:01:47.139Z","dependency_job_id":"f96eb24a-fbd8-4dc5-a3ff-531e47bc63fc","html_url":"https://github.com/duosecurity/duo_universal_nodejs","commit_stats":{"total_commits":65,"total_committers":8,"mean_commits":8.125,"dds":0.7076923076923076,"last_synced_commit":"6a24313aad24d91297a218eeb49436fd983cf06e"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/duosecurity%2Fduo_universal_nodejs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/duosecurity%2Fduo_universal_nodejs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/duosecurity%2Fduo_universal_nodejs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/duosecurity%2Fduo_universal_nodejs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/duosecurity","download_url":"https://codeload.github.com/duosecurity/duo_universal_nodejs/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248143025,"owners_count":21054694,"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":["duo","mfa","nodejs"],"created_at":"2024-09-25T01:45:10.878Z","updated_at":"2025-04-10T02:20:30.461Z","avatar_url":"https://github.com/duosecurity.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Duo Universal Node.js library\n\n[![Build Status](https://github.com/duosecurity/duo_universal_nodejs/workflows/Node.js%20CI/badge.svg)](https://github.com/duosecurity/duo_universal_nodejs/actions/workflows/nodejs-ci.yml)\n[![npm version](https://badge.fury.io/js/@duosecurity%2Fduo_universal.svg)](https://badge.fury.io/js/@duosecurity%2Fduo_universal)\n[![GitHub license](https://img.shields.io/github/license/duosecurity/duo_universal_nodejs)](https://github.com/duosecurity/duo_universal_nodejs/blob/main/LICENSE)\n\nThis library allows a web developer to quickly add Duo's interactive, self-service, two-factor authentication to any Node.js web login form.\n\nSee our developer documentation at https://www.duosecurity.com/docs/duoweb for guidance on integrating Duo 2FA into your web application.\n\nDuo especially thanks [Lukas Hroch](https://github.com/lukashroch) for creating the initial version of this library.\n\n## Getting Started\n\nThis library requires Node.js v14 or later.\n\nTo use this client in your existing developing environment, install it from NPM\n\n```sh\nnpm install @duosecurity/duo_universal\n```\n\nOnce it's installed, see our developer documentation at https://duo.com/docs/duoweb and the `example` folder in this repo for guidance on integrating Duo 2FA into your web application.\n\n### TLS 1.2 and 1.3 Support\n\nDuo_universal_nodejs uses the Node tls library and OpenSSL for TLS operations. All versions of Node receiving security support (14 and higher) use OpenSSL 1.1.1 which supports TLS 1.2 and 1.3.\n\n## Usage Details\n\n### 1. Import client\n\n```ts\nimport { Client } from '@duosecurity/duo_universal';\n```\n\n### 2. Create client\n\nCreates new client instance. Provide your Duo Security application credentials and host URL. Include redirect URL to make a way back to your application.\n\n```ts\nconst client = new Client({\n    clientId: 'yourDuoApplicationClientId',\n    clientSecret: 'yourDuoApplicationSecret',\n    apiHost: 'api-12345678.duosecurity.com',\n    redirectUrl: 'http://localhost:3000/redirect',\n});\n```\n\n### 3. Heath check\n\nDetermines if Duo’s servers are accessible and available to accept the 2FA request.\n\n```ts\nconst status = await client.healthCheck();\n```\n\n### 4. Generate state\n\nGenerates new state (random string) to link the with authentication attempt. Store appropriately, so you can retrieve/compare on callback.\n\n```ts\nconst state = client.generateState();\n```\n\n### 5. Create authentication URL\n\nCreates authentication URL to redirect user to Duo Security Universal prompt. Provide user identifier and state generated in previous step.\n\n```ts\nconst authUrl = client.createAuthUrl('username', 'state');\n```\n\n### 6. Token \u0026 code exchange\n\nExchanges received `duo code` from callback redirect for token result.\n\n```ts\nconst token = await client.exchangeAuthorizationCodeFor2FAResult('duoCode', 'username');\n```\n\n## Example\n\nA complete implementation example can be found in [`example/`](/example).\nIt's a simple express-based application.\nPlease follow the [`example/README.md`](/example/README.md) to spin it up.\n\n## Contribute\n\nFork the repository\n\nInstall dependencies\n\n```sh\nnpm install\n```\n\nMake your proposed changes. Add tests if applicable, lint the code. Submit a pull request.\n\n## Tests\n\n```sh\nnpm run test\n```\n\n## Lint\n\n```sh\nnpm run lint\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fduosecurity%2Fduo_universal_nodejs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fduosecurity%2Fduo_universal_nodejs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fduosecurity%2Fduo_universal_nodejs/lists"}