skutil-express-jwt

1.3.0 • Public • Published

express-jwt together with a sign and a verify method.

Install

yarn add skutil-express-jwt

Usage

const jwt = require('skutil-express-jwt')
jwt.init({
    secret: 'some string',
    algorithms: ['HS256', ...],
    sign: { ... },
    verify: { ... }
})

const token = jwt.sign({ ... })
const decoded = jwt.verify(token)

const app = express()
app.get('/some/uri', jwt.createMidware(), (req, res, next) => {
    const auth = req.auth
    ...
})

Api

jwtUtil.init(options)

options:

  • secret: String
  • algorithms: String[] the algorithms supported in sign and verify
  • sign: jwt.SignOptions all the options of jwt.sign
  • verify: expressjwt.Params all the options of expressjwt

jwtUtil.sign(data, signOptions)

return the signed string.

signOptions: optional, same as jwt.SignOptions, merged with the options.sign part internally.

  • the algorithm is used in the order of signOptions.algorithm > options.sign.algorithm > options.algorithms[0]

jwtUtil.verify(token, verifyOptions)

return the decoded data from token.

verifyOptions: optional, same as jwt.VerifyOptions, merged with the options.verify part internally.

jwtUtil.createMidware()

return a express middleware. use params provided in init function.

Dependencies (1)

Dev Dependencies (4)

Package Sidebar

Install

npm i skutil-express-jwt

Weekly Downloads

3

Version

1.3.0

License

MIT

Unpacked Size

3.4 kB

Total Files

3

Last publish

Collaborators

  • stayknight