denim-api-auth-middleware
v1.0.9
Published
Express API Key Auth Middleware
Downloads
5
Readme
denim-api-auth-middleware
Api Key authorization middleware for Express
Getting Started
yarn add denim-api-auth-middleware
Prerequisites
Tested with Express 4
Installing
install package
yarn add denim-api-auth-middleware
- OR -
npm install denim-api-auth-middleware
most basic setup
import Express from 'express'
import makeApiKeyAuthMiddlware from 'denim-api-auth-middleware'
import http from 'http'
const app = new Express()
//Note: production keys should be randomly generated. See https://github.com/substack/node-hat
const API_KEYS = {
mySecretKey: 'mySecretPassword'
}
const apiKeyAuthMiddlware = makeApiKeyAuthMiddleware(API_KEYS) //initialize
app.use(apiKeyAuthMiddlware) // API Key auth middleware
app.get('/',(req, res)=>{
res.send('Great Success')
})
const server = http.createServer(app)
server.listen(8080, () =>
console.log('HTTP Server Listening on Port',8080)
)
# curl localhost:8080
Forbidden
# curl localhost:8080 \
--header "Authorization: mySecretKey:mySecretPassword"
Great Success
Running the tests
run tests once:
yarn test
watch tests:
yarn test --watch
Deployment
yarn publish
Built With
- node - Node 9.2.0
- prettier-standard - Used for code style
- babel-cli - Used for transpiling and running es6
- babel-preset-env - Used for transpiling and running es6
- jest - Testing framework
- chai - Assertion Library
- husky - Pre-commit hooks
- lint-staged - Linting for changed files
Versioning
We use SemVer for versioning. For the versions available, see the tags on this repository.
Authors
- Michael W. Clark - Initial work - MichaelWClark
License
This project is licensed under the MIT License - see the LICENSE.md file for details