git ssb

16+

cel / patchfoo



Commit 4bfb33a4d47d3c3d5a32dd12169c04be0592ff6b

Optional Basic authentication

Stuart Gathman committed on 7/29/2017, 5:04:16 PM
Parent: b12852a819dd52daeb990c366f744da21388c82e

Files changed

lib/serve.jschanged
lib/serve.jsView
@@ -65,8 +65,27 @@
6565 console.log(this.req.method, this.req.url)
6666 var self = this
6767
6868 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 + }
6988
7089 if (this.req.method === 'POST' || this.req.method === 'PUT') {
7190 if (/^multipart\/form-data/.test(this.req.headers['content-type'])) {
7291 var data = {}

Built with git-ssb-web