-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Import lukashroch/duo_universal_nodejs
Commit 35cd9efb2f6fa78fbe2115b56a3071751966d4ed
- Loading branch information
1 parent
d8c95e4
commit a95013c
Showing
37 changed files
with
16,684 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module.exports = { | ||
root: true, | ||
env: { | ||
node: true, | ||
}, | ||
parser: '@typescript-eslint/parser', | ||
parserOptions: { | ||
ecmaVersion: 2021, | ||
sourceType: 'module', | ||
}, | ||
extends: [ | ||
'eslint:recommended', | ||
'plugin:@typescript-eslint/recommended', | ||
'plugin:prettier/recommended', | ||
], | ||
plugins: ['@typescript-eslint', 'prettier'], | ||
rules: { | ||
'prettier/prettier': 'error', | ||
'@typescript-eslint/no-unused-vars': ['warn', { ignoreRestSiblings: true }], | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
name: Node.js CI | ||
|
||
on: | ||
push: | ||
branches: [ master ] | ||
pull_request: | ||
branches: [ master ] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
node-version: [12.x, 14.x, 16.x] | ||
|
||
steps: | ||
- name: Repository checkout | ||
uses: actions/[email protected] | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/[email protected] | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- name: Install latest npm | ||
run: npm install -g npm | ||
- name: Install dependencies | ||
run: npm ci | ||
- name: Run lint | ||
run: npm run lint | ||
- name: Run build | ||
run: npm run build | ||
- name: Run tests | ||
run: npm run test:coverage | ||
- name: Code coverage | ||
if: ${{ matrix.node-version == '14.x' }} | ||
uses: codecov/codecov-action@v1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
coverage | ||
dist | ||
node_modules | ||
|
||
# Log files | ||
npm-debug.log* | ||
|
||
# Editor directories and files | ||
.idea | ||
.vscode/* | ||
!.vscode/launch.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules/ | ||
dist/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = { | ||
printWidth: 100, | ||
singleQuote: true | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2021 Lukas Hroch | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,97 @@ | ||
This is a place holder for the README | ||
# Duo Universal Node.js library | ||
|
||
[](https://github.com/lukashroch/duo_universal_nodejs/actions/workflows/nodejs-ci.yml) | ||
[](https://app.codecov.io/gh/lukashroch/duo_universal_nodejs) | ||
 | ||
[](https://github.com/lukashroch/duo_universal_nodejs/blob/master/LICENSE) | ||
|
||
Duo Web v4 SDK - Duo Universal Prompt implementation for Node.js | ||
|
||
- follows [Duo Web v4 SDK](https://duo.com/docs/duoweb) implementation | ||
- largely based on Duo Web v4 SDKs for [other languages](https://github.com/duosecurity) | ||
|
||
## Installation | ||
|
||
``` | ||
npm install duo_universal | ||
``` | ||
|
||
## Usage | ||
|
||
Read official Duo Web v4 SDK - Duo Universal Prompt docs (https://duo.com/docs/duoweb) to get familiar with the implementation details. | ||
|
||
### 1. Import client | ||
|
||
```ts | ||
import { Client } from 'duo_universal'; | ||
``` | ||
|
||
### 2. Create client | ||
|
||
Creates new client instance. Provide your Duo Security application credentials and host URL. Include redirect URL to make a way back to your application. | ||
|
||
```ts | ||
const client = new Client({ | ||
clientId: 'yourDuoApplicationClientId', | ||
clientSecret: 'yourDuoApplicationSecret', | ||
apiHost: 'api-12345678.duosecurity.com', | ||
redirectUrl: 'http://localhost:3000/redirect', | ||
}); | ||
``` | ||
|
||
### 3. Heath check | ||
|
||
Determines if Duo’s servers are accessible and available to accept the 2FA request. | ||
|
||
```ts | ||
const status = await client.healthCheck(); | ||
``` | ||
|
||
### 4. Generate state | ||
|
||
Generates new state (random string) to link the with authentication attempt. Store appropriately, so you can retrieve/compare on callback. | ||
|
||
```ts | ||
const state = client.generateState(); | ||
``` | ||
|
||
### 5. Create authentication URL | ||
|
||
Creates authentication URL to redirect user to Duo Security Universal prompt. Provide user identifier and state generated in previous step. | ||
|
||
```ts | ||
const authUrl = client.createAuthUrl('username', 'state'); | ||
``` | ||
|
||
### 6. Token & code exchange | ||
|
||
Exchanges received `duo code` from callback redirect for token result. | ||
|
||
```ts | ||
const token = await client.exchangeAuthorizationCodeFor2FAResult('duoCode', 'username'); | ||
``` | ||
|
||
## Example | ||
|
||
Complete example of implementation can be found in [example folder](https://github.com/lukashroch/duo_universal_nodejs/tree/master/example). It's a simple express-based application. Please follow the README instructions in `example` folder to spin it up. | ||
|
||
## Contribute | ||
|
||
Fork the repository | ||
|
||
Install dependencies | ||
``` | ||
npm install | ||
``` | ||
|
||
Make your proposed changes. Add tests if applicable, lint the code. Submit a pull request. | ||
|
||
## Tests | ||
``` | ||
npm test | ||
``` | ||
|
||
## Lint | ||
``` | ||
npm lint | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
CLIENT_ID= | ||
CLIENT_SECRET= | ||
API_HOST= | ||
REDIRECT_URL=http://localhost:3000/redirect |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module.exports = { | ||
root: true, | ||
env: { | ||
node: true, | ||
}, | ||
parserOptions: { | ||
ecmaVersion: 2021, | ||
sourceType: 'module', | ||
}, | ||
extends: ['eslint:recommended', 'plugin:prettier/recommended'], | ||
plugins: ['prettier'], | ||
rules: { | ||
'prettier/prettier': 'error', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/node_modules | ||
|
||
# Local env files | ||
.env* | ||
!.env-template |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Duo Universal Node.js example | ||
|
||
A simple Node.js web application that serves a logon page integrated with Duo 2FA. | ||
|
||
## Setup | ||
|
||
Clone the repository | ||
``` | ||
git clone https://github.com/lukashroch/duo_universal_nodejs.git | ||
``` | ||
|
||
Navigate to example folder | ||
``` | ||
cd duo_universal_nodejs/example | ||
``` | ||
|
||
Install dependencies | ||
``` | ||
npm install | ||
``` | ||
|
||
Copy .env-template file | ||
``` | ||
cp .env-template .env | ||
``` | ||
|
||
## Run the application | ||
|
||
1. Copy the Client ID, Client Secret, and API Hostname values for your Web SDK application into the .env file | ||
|
||
2. Start the application | ||
``` | ||
npm run start | ||
``` | ||
|
||
3. Navigate to http://localhost:3000 | ||
|
||
4. Log in with enrolled Duo user (any password will work, example doesn't verify first authentication step) |
Oops, something went wrong.