diff options
author | Stuart Gathman <stuart@gathman.org> | 2017-07-29 13:04:16 -0400 |
---|---|---|
committer | cel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519> | 2017-10-01 15:15:30 -1000 |
commit | d1abe1bd49739b5da49e9499e95521e8382d7ab6 (patch) | |
tree | d08ee1152744cbeada8064e9b6cf7769ed173337 | |
parent | 5b2e0985c1eb58df5573111b2081d09a9f489f56 (diff) | |
download | patchfoo-d1abe1bd49739b5da49e9499e95521e8382d7ab6.tar.gz patchfoo-d1abe1bd49739b5da49e9499e95521e8382d7ab6.zip |
Optional Basic authentication
-rw-r--r-- | lib/serve.js | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/serve.js b/lib/serve.js index 6a0bb88..75356a9 100644 --- a/lib/serve.js +++ b/lib/serve.js @@ -66,6 +66,25 @@ Serve.prototype.go = function () { var self = this this.res.setTimeout(0) + var conf = self.app.config.patchfoo || {} + var authtok = conf.auth || null + if (authtok) { + var auth = this.req.headers['authorization'] + var tok = null + //console.log('Authorization: ',auth) + + if (auth) { + var a = auth.split(' ') + if (a[0] == 'Basic') { + tok = Buffer.from(a[1],'base64').toString('ascii') + } + } + if (tok != authtok) { + self.res.writeHead(401, {'WWW-Authenticate': 'Basic realm="Patchfoo"'}) + self.res.end('Not authorized') + return + } + } if (this.req.method === 'POST' || this.req.method === 'PUT') { if (/^multipart\/form-data/.test(this.req.headers['content-type'])) { |