Skip to content

Latest commit

 

History

History
49 lines (37 loc) · 1022 Bytes

readme.md

File metadata and controls

49 lines (37 loc) · 1022 Bytes

Express JWT authorization server ready to use

Usage

const { createServer, LOGGER } = require('node-auth-server')

function checkCredentials (req, res, next) {
  const sub = req.get('encp')

  if (sub === 'guest') {
    LOGGER.info(`Successful login of user ${sub}`)

    req.sub = sub

    next()
    return
  }

  LOGGER.error(`Unsuccessful login of user ${sub}`)

  const err = new Error('Invalid credentials')
  err.status = 401
  next(err)
}

const server = createServer(checkCredentials)
server.listen(process.env.PORT, () => {
  LOGGER.info(`Authorization server started on port ${process.env.PORT}`)
})

Development

Run with Docker:

docker run -v <host-project-path>:<container-project-path> -w <container-project-path> -p 127.0.0.1:<host-port>:<container-port> -it <node-image> sh

./dev/setup.sh
npm install
npm test

Example:

docker run -v /home/reinert/projects/auth:/home/auth -w /home/auth -p 127.0.0.1:3001:3001 -it node:alpine sh

./dev/setup.sh
npm install
npm test