Skip to content

Commit 0bd5e20

Browse files
author
Marcos Kirsch
committed
Retrofit for renamed file, display configurable realm
1 parent 122926f commit 0bd5e20

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

httpserver-basicauth.lua

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,21 @@ function basicAuth.authenticate(header)
99
-- Parse basic auth http header.
1010
-- Returns the username if header contains valid credentials,
1111
-- nil otherwise.
12-
local credentials_enc = header:match("Authorization: Basic ([A-Za-z0-9+/=]+)")
12+
local credentials_enc = header:match("Authorization: Basic ([A-Za-z0-9+/=]+)")
1313
if not credentials_enc then
1414
return nil
1515
end
16-
local credentials = dofile("b64.lc").decode(credentials_enc)
16+
local credentials = dofile("httpserver-b64decode.lc")(credentials_enc)
1717
local user, pwd = credentials:match("^(.*):(.*)$")
1818
if user ~= conf.auth.user or pwd ~= conf.auth.password then
1919
return nil
20-
end
21-
print("httpserver-basicauth: User " .. user .. " authenticated.")
20+
end
21+
print("httpserver-basicauth: User \"" .. user .. "\" authenticated.")
2222
return user
2323
end
2424

2525
function basicAuth.authErrorHeader()
26-
return "WWW-Authenticate: Basic realm=\"nodemcu-httpserver\""
26+
return "WWW-Authenticate: Basic realm=\"" .. conf.auth.realm .. "\""
2727
end
2828

2929
return basicAuth

0 commit comments

Comments
 (0)