express-cookie-token
v0.1.1
Published
Authentication by json web token in cookie. Supports basic and bearer but main focus is on cookieToken.
Downloads
4
Readme
express-cookie-token
Authentication by json web token in cookie. Supports basic and bearer but main focus is on cookieToken.
Usage
const auth = require('express-cookie-token')
const users = [
{ username: 'admin', password: 'admin', token: { access: 'all' } }
]
const jwtOpts = {
cookieToken: 'token',
jwtSecret: 'secret key',
jwtOptions: { expiresIn: '7d' },
}
app.use(auth.cookieToken(jwtOpts))
app.get('/token', auth.basic({users}),
auth.cookieToken.renew(jwtOpts),
auth.token(jwtOpts))
app.use('/', express.static('./static'))
...
auth.basic
setsreq.user
property if username and password fromauthorization: Basic ...
header are validauth.bearer
setsreq.token
property if token fromauthorization: Bearer ...
header is validauth.token
sends signed token in response, gets payload byoptions.getPayload(req)
auth.cookieToken
setsreq.token
property if token from cookie namedoptions.cookieToken
is validauth.cookieToken.renew
setsres.cookie(options.cookieToken, signedToken, {httpOnly: true})
Example
See in example folder.