1.3.0 • Published 8 months ago

skutil-express-jwt v1.3.0

Weekly downloads
-
License
MIT
Repository
-
Last release
8 months ago

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.

1.3.0

8 months ago

1.2.1

8 months ago

1.2.0

1 year ago

1.1.0

2 years ago

1.0.0

2 years ago