Retrofit for renamed file, display configurable realm
This commit is contained in:
parent
122926f9f6
commit
0bd5e20c62
@ -9,21 +9,21 @@ function basicAuth.authenticate(header)
|
|||||||
-- Parse basic auth http header.
|
-- Parse basic auth http header.
|
||||||
-- Returns the username if header contains valid credentials,
|
-- Returns the username if header contains valid credentials,
|
||||||
-- nil otherwise.
|
-- nil otherwise.
|
||||||
local credentials_enc = header:match("Authorization: Basic ([A-Za-z0-9+/=]+)")
|
local credentials_enc = header:match("Authorization: Basic ([A-Za-z0-9+/=]+)")
|
||||||
if not credentials_enc then
|
if not credentials_enc then
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
local credentials = dofile("b64.lc").decode(credentials_enc)
|
local credentials = dofile("httpserver-b64decode.lc")(credentials_enc)
|
||||||
local user, pwd = credentials:match("^(.*):(.*)$")
|
local user, pwd = credentials:match("^(.*):(.*)$")
|
||||||
if user ~= conf.auth.user or pwd ~= conf.auth.password then
|
if user ~= conf.auth.user or pwd ~= conf.auth.password then
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
print("httpserver-basicauth: User " .. user .. " authenticated.")
|
print("httpserver-basicauth: User \"" .. user .. "\" authenticated.")
|
||||||
return user
|
return user
|
||||||
end
|
end
|
||||||
|
|
||||||
function basicAuth.authErrorHeader()
|
function basicAuth.authErrorHeader()
|
||||||
return "WWW-Authenticate: Basic realm=\"nodemcu-httpserver\""
|
return "WWW-Authenticate: Basic realm=\"" .. conf.auth.realm .. "\""
|
||||||
end
|
end
|
||||||
|
|
||||||
return basicAuth
|
return basicAuth
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user