Skip to content

reinert/node-auth-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Ready to use JWT authorization server

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published