mirror of
https://github.com/verdaccio/verdaccio.git
synced 2025-01-06 22:40:26 -05:00
make authentication function async
This commit is contained in:
parent
5cc0187b67
commit
81486f412f
3 changed files with 17 additions and 14 deletions
|
@ -146,9 +146,9 @@ Config.prototype.get_package_setting = function(package, setting) {
|
|||
return undefined
|
||||
}
|
||||
|
||||
Config.prototype.authenticate = function(user, password) {
|
||||
if (this.users[user] == null) return false
|
||||
return crypto.createHash('sha1').update(password).digest('hex') === this.users[user].password
|
||||
Config.prototype.authenticate = function(user, password, cb) {
|
||||
if (this.users[user] == null) return cb(null, false)
|
||||
return cb(null, crypto.createHash('sha1').update(password).digest('hex') === this.users[user].password)
|
||||
}
|
||||
|
||||
module.exports = Config
|
||||
|
|
|
@ -89,8 +89,8 @@ module.exports = function(config_hash) {
|
|||
next()
|
||||
})
|
||||
app.use(Cats.middleware)
|
||||
app.use(basic_auth(function(user, pass) {
|
||||
return config.authenticate(user, pass)
|
||||
app.use(basic_auth(function(user, pass, cb) {
|
||||
config.authenticate(user, pass, cb)
|
||||
}))
|
||||
app.use(express.json({strict: false, limit: config.max_body_size || '10mb'}))
|
||||
app.use(express.compress())
|
||||
|
|
|
@ -76,15 +76,18 @@ module.exports.basic_auth = function basic_auth(callback) {
|
|||
var user = credentials.slice(0, index)
|
||||
, pass = credentials.slice(index + 1)
|
||||
|
||||
if (callback(user, pass)) {
|
||||
req.remoteUser = user
|
||||
next()
|
||||
} else {
|
||||
next({
|
||||
status: 403,
|
||||
msg: 'bad username/password, access denied',
|
||||
})
|
||||
}
|
||||
callback(user, pass, function(err, is_ok) {
|
||||
if (err) return next(err)
|
||||
if (is_ok) {
|
||||
req.remoteUser = user
|
||||
next()
|
||||
} else {
|
||||
next({
|
||||
status: 403,
|
||||
msg: 'bad username/password, access denied',
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue