0
votes

I try to create a simple REST Server using Nodered v0.18. To protect the node i download node-red-contrib-httpauth which can offer Basic credential to access http node. Pretty normal at this stage.

So the node

INPUT:HTTP -> httpauth -> OUTPUT:HTTP

INPUT:HTTP properties

Method = GET
URL = /rest/test.json
Name = Auth

I would want to create multiple login username/password pair. So the best configuration in httpauth is using "File".

I had created a .txt file with these content

username1:realm1:password1
username2:realm1:password2
username3:realm1:password3

Store in E:\somefilename.txt

Then I Add new node-red-contribs-httpauthfile

Name = anyname
Auth Type = Basic
Realm = realm1
File = E:\somefilename.txt

In Edit HTTP auth node page

Name = anyname
Auth Type = Basic
Realm = realm1
Username = 
Password = 
Hashed = false or untick

Then I go to URL http://thisismytestdomain.com:1880/rest/test.json Basic credential dialog pop up "at least this part working"

I try to put username1, username2 cannot log in or the wrong credential. Then it goes through with username3 I try to change the hierarchy like

username3:realm1:password3
username2:realm1:password2
username1:realm1:password1

It always the bottom one get authenticated.

Not sure why. Try to google and go to GitHub to understand the code. No luck The code in GitHub looks logic and should be working but not sure why it always able to pick the last entry only.

2

2 Answers

1
votes

This is a bit of a guess, because I haven't actually tried it.

Looking at the source code, here it splits the lines in the file using "\n". On the assumption your file has CR/LF endings, the first password would be suffixed with a CR, and the 2nd to 2nd-last usernames would be prefixed with a CR. And therefore the only one which would be interpreted correctly is the last - which is what you're seeing.

If this is the case, you would have to edit your file to have Unix-style line endings (just LF) rather than DOS/Windows-style (CR/LF).

By the way, somebody called oups13 (is this you?) raised an issue on this in June 2018 which has gone unanswered (see https://github.com/endemecio02/node-red-contrib-httpauth/issues/5). So you're not the only one with the problem.

0
votes

Manage to try with Nodered v0.18 with httpauth V1.0.12 *hopefully in a future update this issue will be solved.

Thanks to Micheal for pointing it out and yes the reason only last username/password be selected is because of DOS/Windows Line Ending CRLF.

So people who use Unix might have no problem but I using windows 10 and notepad. Notepad only has line ending, CRLF. So i had to download notepad++,

Go to Edit->EOL onversion-> UNIX/OSX format

For extra precaution, I save file with UTF-8 encoding. (remember notepad save as ANSI encoding).

then I put the file in E:\unixEOL.txt

Then i go to httpauth node then point to this new files. Now i can access all 3 username & password pairs.