aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorStuart Gathman <stuart@gathman.org>2017-07-29 13:04:16 -0400
committercel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2017-10-01 15:15:30 -1000
commitd1abe1bd49739b5da49e9499e95521e8382d7ab6 (patch)
treed08ee1152744cbeada8064e9b6cf7769ed173337 /lib
parent5b2e0985c1eb58df5573111b2081d09a9f489f56 (diff)
downloadpatchfoo-d1abe1bd49739b5da49e9499e95521e8382d7ab6.tar.gz
patchfoo-d1abe1bd49739b5da49e9499e95521e8382d7ab6.zip
Optional Basic authentication
Diffstat (limited to 'lib')
-rw-r--r--lib/serve.js19
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'])) {