Merge pull request #232 from resin-io/231-header-auth

WIP: Allow using an HTTP header for auth
This commit is contained in:
Pablo Carranza Vélez 2016-08-16 18:00:55 -03:00 committed by GitHub
commit 016a82586e
2 changed files with 8 additions and 1 deletions

View File

@ -1,3 +1,4 @@
* Allow using an HTTP header for auth [Pablo]
* Add iptables rules to block requests to the supervisor API from all interfaces except vpn, docker and local [Pablo]
# v1.13.2

View File

@ -17,9 +17,15 @@ module.exports = (application) ->
parsedRouter.use(bodyParser())
api.use (req, res, next) ->
queryKey = req.query.apikey
header = req.get('Authorization') ? ''
match = header.match(/^ApiKey (\w+)$/)
headerKey = match?[1]
utils.getOrGenerateSecret('api')
.then (secret) ->
if bufferEq(new Buffer(req.query.apikey), new Buffer(secret))
if queryKey? && bufferEq(new Buffer(queryKey), new Buffer(secret))
next()
else if headerKey? && bufferEq(new Buffer(headerKey), new Buffer(secret))
next()
else
res.sendStatus(401)