nodenv-basic-auth
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 = user1export basicauth_password = pass1# add more users export basicauth_user2 = user2export basicauth_password2 = pass2export basicauth_user_mike = mikeexport basicauth_password_mike = secret
Install
$ npm install nodenv-basic-auth
Usage
// Initialize nodenv-basic-authvar NodenvBasicAuth = ;var auth = ;// enable auth on routeapp;
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' ...