polywoo-ba

basic auth

Usage no npm install needed!

<script type="module">
  import polywooBa from 'https://cdn.skypack.dev/polywoo-ba';
</script>

README

BA

basic auth

Install

npm install polywoo-ba

Usage

Create auth header

import { BAAuth } from 'polywoo-ba';

const ba = BAAuth(clientId, clientSecret);
const header = ba('post', '/somepath', new Date());

// header example
{
    Date: Fri, 29 Mar 2019 23:34:53 GMT
    Authorization:POLYWOO abc:frJIzyUNadUthaoUDzLCwozllqg=
}

Verify middleware

import { middleware } from 'polywoo-ba';

// koa app
app.use(
    middleware({
        includeUriList: ['/auth/*'],
        excludeUriList: ['/anoy/*'],
        getApp: clientId => {
            // find ba app info
            return {
                client_id: 'abc',
                client_secret: 'xxx'
            };
        }
    })
);

// access ba user info
ctx.baUser;