1.3.0 • Published 2 years ago
skutil-express-jwt v1.3.0
express-jwt together with a sign and a verify method.
Install
yarn add skutil-express-jwtUsage
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:Stringalgorithms:String[]the algorithms supported in sign and verifysign:jwt.SignOptionsall the options of jwt.signverify:expressjwt.Paramsall 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.