mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2024-12-19 13:47:54 +00:00
Allow using an HTTP header for auth
This commit is contained in:
parent
439bac6331
commit
1eb63366ee
@ -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]
|
* Add iptables rules to block requests to the supervisor API from all interfaces except vpn, docker and local [Pablo]
|
||||||
|
|
||||||
# v1.13.2
|
# v1.13.2
|
||||||
|
@ -17,9 +17,15 @@ module.exports = (application) ->
|
|||||||
parsedRouter.use(bodyParser())
|
parsedRouter.use(bodyParser())
|
||||||
|
|
||||||
api.use (req, res, next) ->
|
api.use (req, res, next) ->
|
||||||
|
queryKey = req.query.apikey
|
||||||
|
header = req.get('Authorization') ? ''
|
||||||
|
match = header.match(/^ApiKey (\w+)$/)
|
||||||
|
headerKey = match?[1]
|
||||||
utils.getOrGenerateSecret('api')
|
utils.getOrGenerateSecret('api')
|
||||||
.then (secret) ->
|
.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()
|
next()
|
||||||
else
|
else
|
||||||
res.sendStatus(401)
|
res.sendStatus(401)
|
||||||
|
Loading…
Reference in New Issue
Block a user