express-cookie-token

0.1.1 • Public • Published

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 sets req.user property if username and password from authorization: Basic ... header are valid
  • auth.bearer sets req.token property if token from authorization: Bearer ... header is valid
  • auth.token sends signed token in response, gets payload by options.getPayload(req)
  • auth.cookieToken sets req.token property if token from cookie named options.cookieToken is valid
  • auth.cookieToken.renew sets res.cookie(options.cookieToken, signedToken, {httpOnly: true})

Example

See in example folder.

Readme

Keywords

none

Package Sidebar

Install

npm i express-cookie-token

Weekly Downloads

0

Version

0.1.1

License

MIT

Last publish

Collaborators

  • grabantot