Skip to content

Commit

Permalink
feature: allow third party apps to integrate with security
Browse files Browse the repository at this point in the history
Specifically done to enable security for node
  • Loading branch information
sbender9 committed Jun 16, 2018
1 parent 00bf953 commit 3ee4060
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions lib/tokensecurity.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,23 @@ module.exports = function (app, config) {
app.put('/signalk/v1/*', writeAuthenticationMiddleware(false))
}

strategy.validateLogin = function (userName, password, cb) {
var configuration = getConfiguration()
var user = configuration.users.find(user => user.username == userName)
if (!user) {
cb(false)
}
bcrypt.compare(password, user.password, (err, matches) => {
cb(matches)
})
}

strategy.getUserType = function (userName) {
var configuration = getConfiguration()
var user = configuration.users.find(user => user.username == userName)
return user ? user.type : null
}

strategy.generateToken = function (req, res, next, id, expiration) {
var configuration = getConfiguration()
var payload = { id: id }
Expand All @@ -235,6 +252,11 @@ module.exports = function (app, config) {
res.send(token)
}

strategy.allowReadOnly = function () {
var configuration = getConfiguration()
return configuration.allow_readonly
}

strategy.allowRestart = function (req) {
return req.isAuthenticated && req.user.type == 'admin'
}
Expand Down

0 comments on commit 3ee4060

Please sign in to comment.