@wdalmut/one-of

0.2.0 • Public • Published

One Of

Build Status

npm install --save @wdalmut/one-of

A simple auth middleware to support one of many authentication methods

const auth = require('@wdalmut/mini-auth');
const token = require('@wdalmut/token-auth');
const basic = require('@wdalmut/basic-auth');
const one_of = require('@wdalmut/one-of');

app.get(
    "/",
    auth(one_of([token(from_token), basic(from_basic)]),
    homePage
);

where from_token and from_basic are simple functions that will returns a promise

const from_token = (token) => {
    return Promise.resolve({id: 1});
};

const from_basic = (username, password) => {
    return Promise.resolve({id: 1});
};

If one authentication mechanism resolve the promise the authentication is considered valid otherwise a 401 is immediately returned.

Readme

Keywords

none

Package Sidebar

Install

npm i @wdalmut/one-of

Weekly Downloads

26

Version

0.2.0

License

MIT

Unpacked Size

7.93 kB

Total Files

6

Last publish

Collaborators

  • wdalmut