0.2.0 • Published 4 years ago

@wdalmut/one-of v0.2.0

Weekly downloads
280
License
MIT
Repository
github
Last release
4 years ago

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.

0.2.0

4 years ago

0.1.0

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.0.1

6 years ago