fix reesh api
CI / changes (push) Successful in 1s
CI / docker-bff (push) Successful in 1s
CI / docker-product (push) Failing after 1s

This commit is contained in:
2026-08-10 18:48:58 +08:00
parent 9865f7dae9
commit afc8e18635
11 changed files with 149 additions and 29 deletions
+9 -10
View File
@@ -20,7 +20,6 @@ function _M.access(conf, ctx)
local service_code = core.request.header(ctx, "authorization-type")
local req_auth = core.request.header(ctx, "authorization-auth")
local refresh = core.request.header(ctx, "refresh")
core.log.info("RAW_HEADER_DEBUG: refresh=["..(refresh or "").."], service_code=["..(service_code or "").."], token=["..(user_key or "").."]")
local skip_auth = white_list[request_uri]
if skip_auth then
@@ -29,10 +28,10 @@ function _M.access(conf, ctx)
else
-- 非白名单完整鉴权逻辑
if not user_key or user_key == "" then
return core.response.exit(401, {code = 10003, message = "未登录"})
return core.response.exit(200, {code = 10003, message = "未登录"})
end
if not service_code or service_code == "" then
return core.response.exit(401, {code = 10003, message = "未登录"})
return core.response.exit(200, {code = 10003, message = "未登录"})
end
local redis_config = core.config.local_conf().redis or {}
@@ -47,13 +46,13 @@ function _M.access(conf, ctx)
local ok, err = red:connect(redis_host, redis_port)
if not ok then
red:set_keepalive(10000, 100)
return core.response.exit(500, {code = 10003, message = "系统错误,请稍后重试"})
return core.response.exit(200, {code = 10003, message = "系统错误,请稍后重试"})
end
if redis_password ~= "" then
local auth_ok, auth_err = red:auth(redis_password)
if not auth_ok then
red:set_keepalive(10000, 100)
return core.response.exit(500, {code = 10003, message = "系统错误,请稍后重试"})
return core.response.exit(200, {code = 10003, message = "系统错误,请稍后重试"})
end
end
if redis_db > 0 then
@@ -63,21 +62,21 @@ function _M.access(conf, ctx)
local res, err = red:get(redis_key)
red:set_keepalive(10000, 100)
if err or res == ngx.null then
return core.response.exit(401, {code = 10003, message = "未登录或登录已过期"})
return core.response.exit(200, {code = 10003, message = "未登录或登录已过期"})
end
local json, decode_err = core.json.decode(res)
if not json then
return core.response.exit(500, {code = 10003, message = "数据解析错误"})
return core.response.exit(200, {code = 10003, message = "数据解析错误"})
end
if service_code == "admin1" then
if not req_auth or req_auth == "" then
return core.response.exit(403, {code = 10008, message = "没有权限访问该资源"})
return core.response.exit(200, {code = 10008, message = "没有权限访问该资源"})
end
local roles = json.roles or {}
local expect_path = roles[req_auth]
if not expect_path then
return core.response.exit(403, {code = 10008, message = "没有权限访问该资源"})
return core.response.exit(200, {code = 10008, message = "没有权限访问该资源"})
end
local full_expect_uri = "/" .. expect_path
local match = false
@@ -88,7 +87,7 @@ function _M.access(conf, ctx)
end
end
if request_uri ~= full_expect_uri and not match then
return core.response.exit(403, {code = 10008, message = "没有权限访问该资源"})
return core.response.exit(200, {code = 10008, message = "没有权限访问该资源"})
end
end