[
{
"id": "7025310b.bd649",
"type": "http in",
"z": "60bba61b.c39738",
"name": "",
"url": "/basic-auth-test",
"method": "get",
"upload": false,
"swaggerDoc": "",
"x": 310,
"y": 200,
"wires": [
[
"fd50f5fa.b7f118"
]
]
},
{
"id": "e5bd0dd7.b90a08",
"type": "http response",
"z": "60bba61b.c39738",
"name": "",
"statusCode": "200",
"headers": {},
"x": 640,
"y": 200,
"wires": []
},
{
"id": "fd50f5fa.b7f118",
"type": "function",
"z": "60bba61b.c39738",
"name": "Check Basic Auth",
"func": "let upc;\n\nlet userlist = [\n \"this:that\"\n ];\n \ntry {\n \n if (msg.req.headers && msg.req.headers.authorization\n ) {\n let base = msg.req.headers.authorization.split(\" \")[1]\n let buff = new Buffer(base, 'base64');\n upc = buff.toString('ascii');\n }\n \n \n if (upc && userlist.includes(upc)\n ) {\n msg.username = upc.split(\":\")[0]\n return [msg,null];\n } else {\n msg.headers = {\"WWW-Authenticate\": \"Basic\"}\n msg.statusCode = 401\n return [null,msg];\n }\n\n} catch (err) {node.warn(err)}",
"outputs": 2,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 470,
"y": 360,
"wires": [
[
"e5bd0dd7.b90a08"
],
[
"53d6b4f.bd5774c"
]
]
},
{
"id": "53d6b4f.bd5774c",
"type": "http response",
"z": "60bba61b.c39738",
"name": "",
"statusCode": "401",
"headers": {},
"x": 520,
"y": 420,
"wires": []
}
]
Add this, visit page, enter user "this" password "that", then visit admin page, see problem.