Use in conjunction with koa-login.
This middleware can be used to secure routes in koa.
It will look for a JSON Web Token (JWT) inside the X-Auth-Token
request header.
If no token is present or it is invalid a http response code 401 unauthorized
will be sent back.
Otherwise the this.state.user
object will be populated with the decoded data from the jwt.
$ npm install koa-auth-jwt
var auth = require('koa-auth-jwt');
// register unsecured routes here
app.use(auth({
secret: process.env.SECRET,
token: 'X-Auth-Token' // optional
});
// register secured routes here
secret
mandatory string which has been used to sign the jwttoken
optional string defining which header should contain the token
$ npm install -g mocha
$ mocha