Authorization -> Proxy-Authorization

This commit is contained in:
Kay0u 2020-12-23 18:13:34 +01:00
parent a756462e6c
commit 0ff5cc6af7
No known key found for this signature in database
GPG key ID: AAFEEB16CFA2AE2D

View file

@ -263,14 +263,14 @@ function refresh_logged_in()
return false return false
end end
-- If client set the `Authorization` header before reaching the SSO, -- If client set the `Proxy-Authorization` header before reaching the SSO,
-- we want to match user and password against the user database. -- we want to match user and password against the user database.
-- --
-- It allows to bypass the cookie-based procedure with a per-request -- It allows to bypass the cookie-based procedure with a per-request
-- authentication. This is useful to authenticate on the SSO during -- authentication. This is useful to authenticate on the SSO during
-- curl requests for example. -- curl requests for example.
function parse_auth_header() function parse_auth_header()
local auth_header = ngx.req.get_headers()["Authorization"] local auth_header = ngx.req.get_headers()["Proxy-Authorization"]
if auth_header then if auth_header then
_, _, b64_cred = string.find(auth_header, "^Basic%s+(.+)$") _, _, b64_cred = string.find(auth_header, "^Basic%s+(.+)$")
@ -295,6 +295,9 @@ function parse_auth_header()
else else
return redirect(conf.portal_url) return redirect(conf.portal_url)
end end
else
-- https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/407
ngx.status = 407
end end
end end
end end
@ -426,8 +429,8 @@ end
-- application underneath. -- application underneath.
function set_headers(user) function set_headers(user)
local user = user or authUser local user = user or authUser
-- Set `authorization` header to enable HTTP authentification -- Set `Proxy-Authorization` header to enable HTTP authentification
ngx.req.set_header("Authorization", "Basic "..ngx.encode_base64( ngx.req.set_header("Proxy-Authorization", "Basic "..ngx.encode_base64(
user..":"..cache:get(user.."-password") user..":"..cache:get(user.."-password")
)) ))