Files
expressjs.com/_includes/api/en/3x/mw-basicAuth.md
Douglas Christopher Wilson faa6bb9e0a Apply StandardJS style to API docs
2019-05-26 22:47:09 -04:00

570 B

basicAuth()

Basic Authentication middleware, populating req.user with the username.

Simple username and password:

app.use(express.basicAuth('username', 'password'))

Callback verification:

app.use(express.basicAuth(function (user, pass) {
  return user === 'tj' && pass === 'wahoo'
}))

Async callback verification, accepting fn(err, user), in this case req.user will be the user object passed.

app.use(express.basicAuth(function (user, pass, fn) {
  User.authenticate({ user: user, pass: pass }, fn)
}))