Skip to content

marc1404/koa-auth-jwt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

koa-auth-jwt

npm Travis Code Climate Code Climate npm npm

David David

Description

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.

Installation

$ npm install koa-auth-jwt

Usage

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

Options

  • secret mandatory string which has been used to sign the jwt
  • token optional string defining which header should contain the token

Test

$ npm install -g mocha  
$ mocha

Author

marc1404

License

MIT

About

Koa auth middleware using JWT

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published