skutil-express-jwt
v1.3.0
Published
express-jwt together with a sign method.
Downloads
7
Readme
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 verifysign
:jwt.SignOptions
all the options of jwt.signverify
: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.