Nobel Prize Magnet

    simple-hmac-auth-koa
    TypeScript icon, indicating that this package has built-in type declarations

    1.4.0 • Public • Published

    simple-hmac-auth-koa

    Koa middleware for creating APIs that implement simple-hmac-auth.

    ci coverage npm license

    Usage

    Instantiating the middleware requires a function that can return a secret for a given API key.

    If a request fails authentication, it will throw a 401 error.

    The simple-hmac-auth authentication protocol requires the raw body of a request to validate it. simple-hmac-auth-koa leverages koa-bodyparser to parse body data. However, because the body parser only supports json, form and text input, this project is currently limited to those inputs as well.

    import Koa from 'koa';
    import Router from 'koa-router';
    import auth from 'simple-hmac-auth-koa';
    const app = new Koa();
    
    // Enable authentication
    
    app.use(auth({
      secretForKey: async apiKey => {
        // Return the correct secret for the given API key
        return 'SECRET';
      }
    }));
    
    // Route incoming requests
    
    const router = new Router();
    
    router.all('/', ctx => {
      ctx.body = 'Request successful.';
    });
    
    app.use(router.routes());
    app.use(router.allowedMethods());
    
    // Listen
    
    app.listen(8000);

    License

    MIT © Jesse Youngblood

    Keywords

    none

    Install

    npm i simple-hmac-auth-koa

    DownloadsWeekly Downloads

    338

    Version

    1.4.0

    License

    MIT

    Unpacked Size

    9.78 kB

    Total Files

    5

    Last publish

    Collaborators

    • jessety