Nearly Perpendicular Macaroons

    nodenv-basic-auth

    0.1.1 • Public • Published

    nodenv-basic-auth

    NPM Version Node.js Version

    nodenv-basic-auth extend the package basic-auth with express or connect middleware layer and the function to extract user credentials from environment variables.
    To get/set user credentials dynamically is very useful on PaaS platforms like heroku. This give you the ability to enable or disable basic-auth and set multiple user credentials without deploy your product for any of these changes.

    To add user through environment variable both parameters, username and password, are required. By default the prefix for username is basicauth_user and for password basicauth_pass.
    To add multiple users, add an additional idententication string to parameter name. This additional string must be same for username and password.

    Example

    export basicauth_user = user1
    export basicauth_password = pass1
    # add more users 
    export basicauth_user2 = user2
    export basicauth_password2 = pass2
    export basicauth_user_mike = mike
    export basicauth_password_mike = secret

    Install

    $ npm install nodenv-basic-auth
    

    Usage

    // Initialize nodenv-basic-auth
    var NodenvBasicAuth = require('nodenv-basic-auth');
    var auth = new NodenvBasicAuth();
    // enable auth on route
    app.get('/home', auth, function(req, res) {
     res.send('Hello World');
    });

    Extend usage

    nodenv-basic-auth accept 2 parameters on initialisation. First parameter is options which give you the possibility to set environment naming convention for credential.
    The second parameter 'users' transmit user credentials.

    Options

    Object properties:
    userPrefix
    Environment prefix to identify username. Default basicauth_user

    passPrefix
    Environment postfix to identify password. Default basicauth_pass

    Users

    Object to transmit user credentials:

    var defaultUsers = {
      mike: 'secret',
      john: 'secret',
      ... 
    }

    License

    MIT

    Install

    npm i nodenv-basic-auth

    DownloadsWeekly Downloads

    1

    Version

    0.1.1

    License

    MIT

    Last publish

    Collaborators

    • nahody