@amdglobal/koa-bearer-token
v1.1.2
Published
Bearer token parser middleware for koa
Downloads
20
Maintainers
Readme
koa-bearer-token
Bearer token parser middleware for koa
Inspired by express-bearer-token
Compatibility table
| koa version | koa-bearer-token version |
|:-----------:|:------------------------:|
| <2
| 0.x.x
|
| 2
| 1.x.x
|
Install
$ npm install koa-bearer-token
Usage
Use with koa-bodyparser
const Koa = require('koa')
const bodyParser = require('koa-bodyparser');
const bearerToken = require('koa-bearer-token')
const app = new Koa()
app.use(bodyParser())
app.use(bearerToken())
app.use(function (ctx) {
// ctx.request.token
})
app.listen(3000)
Provide in header
Authorization: Bearer <token>
Provide in query
?access_token=<token>
Provide in body
access_token=<token>
Customize
app.use(bearerToken({
bodyKey: 'access_token',
queryKey: 'access_token',
headerKey: 'Bearer',
reqKey: 'token'
}))
License
MIT © C. T. Lin