Older/Server/lua/basic_authentication_proxy.lua

23 lines
871 B
Lua
Raw Normal View History

2024-06-18 00:27:43 +08:00
local session, err, exists = require "resty.session".open()
if exists and session:get("authenticated") then
local account = session:get("account")
ngx.log(ngx.INFO, session:get("account"), " 访问")
local accounts = require("lua/accounts")
local credentials = accounts.credentials()
local password = ""
if credentials then
password = credentials[account]
end
local auth_value = ngx.encode_base64(account .. ':' .. password)
ngx.req.set_header("Authorization", "Basic " .. auth_value)
else
local server = ""
if ngx.var.server_port == "80" then
server = ngx.var.host
else
server = ngx.var.host .. ":" .. ngx.var.server_port
end
local target_url = ngx.var.scheme .. "://" .. server .. ngx.var.request_uri
ngx.redirect('https://amass.fun/LoginPage?next=' .. ngx.escape_uri(target_url))
end