Commit 4bfb33a4d47d3c3d5a32dd12169c04be0592ff6b
Optional Basic authentication
Stuart Gathman committed on 7/29/2017, 5:04:16 PMParent: b12852a819dd52daeb990c366f744da21388c82e
Files changed
lib/serve.js | changed |
lib/serve.js | ||
---|---|---|
@@ -65,8 +65,27 @@ | ||
65 | 65 … | console.log(this.req.method, this.req.url) |
66 | 66 … | var self = this |
67 | 67 … | |
68 | 68 … | this.res.setTimeout(0) |
69 … | + var conf = self.app.config.patchfoo || {} | |
70 … | + var authtok = conf.auth || null | |
71 … | + if (authtok) { | |
72 … | + var auth = this.req.headers['authorization'] | |
73 … | + var tok = null | |
74 … | + //console.log('Authorization: ',auth) | |
75 … | + | |
76 … | + if (auth) { | |
77 … | + var a = auth.split(' ') | |
78 … | + if (a[0] == 'Basic') { | |
79 … | + tok = Buffer.from(a[1],'base64').toString('ascii') | |
80 … | + } | |
81 … | + } | |
82 … | + if (tok != authtok) { | |
83 … | + self.res.writeHead(401, {'WWW-Authenticate': 'Basic realm="Patchfoo"'}) | |
84 … | + self.res.end('Not authorized') | |
85 … | + return | |
86 … | + } | |
87 … | + } | |
69 | 88 … | |
70 | 89 … | if (this.req.method === 'POST' || this.req.method === 'PUT') { |
71 | 90 … | if (/^multipart\/form-data/.test(this.req.headers['content-type'])) { |
72 | 91 … | var data = {} |
Built with git-ssb-web