Support HTTP BasicAuth for authentication with auth-user argument, password or hashedPassword#7173
Support HTTP BasicAuth for authentication with auth-user argument, password or hashedPassword#7173gaberudy wants to merge 2 commits intocoder:mainfrom
Conversation
buenos-nachos
left a comment
There was a problem hiding this comment.
Thank you for the contribution! Ended up leaving two small comments, but I'm worried I don't have enough architectural understanding of the project to give more finer-grained feedback
@bcpeinhardt @code-asher Pinging you just so you're aware of this PR
| args.password = process.env.PASSWORD | ||
| } | ||
|
|
||
| const usingEnvAuthUser = !!process.env.AUTH_USER |
There was a problem hiding this comment.
If this variable isn't going to be used for another 50+ lines, I think it'd be better to inline it inside the return type
| try { | ||
| const base64Credentials = authHeader.split(" ")[1] | ||
| const credentials = Buffer.from(base64Credentials, "base64").toString("utf-8") | ||
| const [username, password] = credentials.split(":") | ||
| if (username !== authUser) return false | ||
| if (hashedPassword) { | ||
| return await isHashMatch(password, hashedPassword) | ||
| } else { | ||
| return safeCompare(password, authPassword || "") | ||
| } | ||
| } catch (error) { | ||
| logger.error("Error validating basic auth:" + error) | ||
| return false | ||
| } |
There was a problem hiding this comment.
Could the logic for base64Credentials be updated to check that the split array has an element at index 1, and isn't potentially undefined? Once that's done, could the declaration be moved out of the block since that part of the code wouldn't be able to throw an error?
13754f3 to
cc3c22d
Compare
|
Closing for now but happy to re-review if you come back to this. |
|
I would like to continue this if @gaberudy is no longer interested. I want to intergrate external authentication without setting |
|
@tachibanayui that would be awesome. If you do tackle this, one thought I had: I wonder if instead of a separate |
|
Since this is intended for single user anyway, we can hard code the username |
|
Good point, I like the sound of that. |
Fixes #7142
Supersedes previous pull request #7143