0.2.4 • Published 1 year ago

@codealpha/oauth2 v0.2.4

Weekly downloads
10
License
MIT
Repository
github
Last release
1 year ago

AuthN

Faux IAM.

reference material:

Installation

npm i @codealpha/oauth2 --save

Example

import {oauth} from '@codealpha/oauth2'
const oauthConfig = {...}

const Server = async () => {
  const { authN, authZ } = await oauth(oauthConfig);

  app
    .use(express.static(path.join(__dirname, "public")))
    .use("/auth", authN)
    .use("/private/stuff", [
      authZ,
      (req, res) => {
        res.send({ message: "welcome VIP", data: ["a", 2, { b: true }] });
      },
    ])
    .listen(5000, () => {
      console.log(`OAuth2 Server started at http://localhost:5000`);
    });
};

Usage

authN

.use("/auth", authN)

"/ui":

  • AS User Interface

"/client":

  • data about the website using the AS

"/user/whoami":

  • user object

authZ

.use("/private/stuff",
      authZ,
      (req, res) => {
        res.send({ message: "welcome VIP", data: ["a", 2, { b: true }] });
      },
    )

ClientSide Callback workflow

Post login: 1) client website recieves authCode. 2) client website exchanges authCode for authToken. 3) client website uses authToken to make API requests.

Configuration

const oauthConfig = {
  database: {
    type: "postgres",
    config: {
      user: "DATABASE_USERNAME",
      host: "DATABASE_HOST",
      password: "DATABASE_PASSWORD",
      port: 5432,
    },
  },
};
keyDescriptionDefault
awsCredentialsPaththe absolute file path to the AWS credentials.json file
mfaRequireda SMS code is required on login in addition to a username/password.false
emailSalta bcrypt salt used to encrypt data at restno encryption
database *
database.typetype of databasestring
database.configconfiguration object specific to a databaseObject
client
client.namename of website using OAuth2'OAuth2Placeholder'
client.websitefqdn of website using OAuth2'OAuth2Placeholder'
client.badgeUrlurl of brand image used to customize OAuth2 pages
registrationWhitelistonly allow a defined list of usernames to registerany

Running Example (dev mode)

Authentication Server UI

1) Start client 1) cd to /client 2) run:

    ```bash
    npm start
    ```

Build server & end-user functions

2) Setup initial builds and watch for changes. 1) from project root 2) run:

    ```bash
    npm run cli start
    ```

Example end-user application

3) Start Example - make sure your postgres database is up and running. - fill in correct environment variables 1) from project root 2) run:

    ```bash
    npm run cli example
    ```

Publishing npm module.

1) Create NPM granular access token. StackOverflow ref 1) run:

    ```bash
    npm config set _authToken=GRANULAR_ACCESS_TOKEN
    ```
    * if you get an error like `Invalid auth configuration found: '_authToken' must be renamed to '//registry.npmjs.org/:_authToken' in user config`.
    1) run:
        ```bash
        npm config fix
        ```

2) Publish to NPM. 1) from project root 2) run:

    ```bash
    npm run publishit
    ```
0.2.1

1 year ago

0.2.3

1 year ago

0.2.2

1 year ago

0.2.4

1 year ago

0.1.18

3 years ago

0.1.14

3 years ago

0.1.17

3 years ago

0.1.12

3 years ago

0.1.13

3 years ago

0.1.11

3 years ago

0.1.10

3 years ago

0.1.9

3 years ago

0.1.8

3 years ago

0.1.7

3 years ago

0.1.6

4 years ago

0.1.5

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago