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
Versioning
We use SemVer for versioning. For the versions available, see the tags on this repository.
Authors
License
This project is licensed under the MIT License - see the LICENSE.md file for details