This commit is contained in:
2021-11-28 15:40:07 +08:00
parent d9cdb86e8e
commit 405cc14d00
2 changed files with 20 additions and 28 deletions
+1 -1
View File
@@ -46,7 +46,7 @@ server {
# ➤ sudo chown (whoami) /usr/local/file_upload
set $tmp_file_dir "/usr/local/file_upload"; # 文件存储路径
set $task_server "http://127.0.0.1:8080"; # task server host
set $htyuc "http://127.0.0.1:8088"; #htyuc host
set $htyuc "http://127.0.0.1:3000"; #htyuc host
set $resty_loc "/usr/local/opt/openresty"; # MacOS
set $convert "/usr/local/bin/convert";
+19 -27
View File
@@ -59,8 +59,7 @@ local function verifyJwtToken(token)
local httpc = http.new()
local remote_url = string.format("%s/api/v1/uc/verify_jwt_token", htyuc)
ngx.log(ngx.INFO, 'HTYUC REMOTE_URL -> ', remote_url)
ngx.log(ngx.INFO, 'Authorization -> ', token)
ngx.log(ngx.INFO, 'HTYUC REMOTE_URL -> ' .. remote_url)
local res, err = httpc:request_uri(
remote_url,
@@ -76,16 +75,16 @@ local function verifyJwtToken(token)
if not res then
ngx.status = ngx.HTTP_UNAUTHORIZED
ngx.header.content_type = "application/json; charset=utf-8"
ngx.log(ngx.ERR, "CAN'T VERIFY JWT TOKEN!")
ngx.log(ngx.ERR, "CAN'T VERIFY JWT TOKEN -> ", err)
ngx.exit(ngx.HTTP_UNAUTHORIZED)
else
if 200 ~= res.status then
ngx.log(ngx.ERR, "JWT TOKEN VERIFICATION ERROR!", err)
ngx.log(ngx.ERR, "JWT TOKEN VERIFICATION *ERROR* -> ", err)
ngx.exit(res.status)
end
end
ngx.log(ngx.INFO, "JWT TOKEN VERIFICATION PASSED.")
ngx.log(ngx.INFO, "JWT TOKEN VERIFICATION *PASSED*.")
end
@@ -101,36 +100,29 @@ local function decodeJwtClaim(jwtClaim)
ngx.exit(ngx.HTTP_UNAUTHORIZED)
end
ngx.log(ngx.INFO, "DECODED JWT CLAIM -> " .. jwtObj)
ngx.log(ngx.INFO, "DECODED JWT CLAIM -> " .. cjson.encode(jwtObj))
local htyToken = cjson.decode(jwtObj.payload.sub)
ngx.log(ngx.INFO, "DECODED JWT TOKEN -> " .. htyToken)
ngx.log(ngx.INFO, "DECODED JWT TOKEN -> " .. cjson.encode(htyToken))
return htyToken
end
local authHeader = ngx.req.get_headers().Authorization
local sudoerToken = ngx.req.get_headers().HtySudoerToken
-- if authHeader then
-- ngx.log(ngx.INFO, 'CHECK_AUTH_HEADER -> ', authHeader)
-- local token = decodeJwtClaim(authHeader)
-- verifyJwtToken(token)
-- else
-- ngx.log(ngx.ERR, 'Request header no authorization ! ')
-- ngx.status = 500
-- ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)
-- end
--
-- if sudoerToken then
-- ngx.log(ngx.INFO, 'Check request authorization HtySudoerToken -> ', sudoerToken)
-- -- local htyToken = DecoderJwtToken(authorization)
-- --verifyJwtToken(sudoerToken)
-- else
-- ngx.log(ngx.ERR, 'Request header no hty sudoer token ! ')
-- ngx.status = 500
-- ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)
-- end
if authHeader then
ngx.log(ngx.INFO, 'CHECK_AUTH_HEADER -> ', authHeader)
local token = decodeJwtClaim(authHeader)
verifyJwtToken(token)
elseif sudoerToken then
ngx.log(ngx.INFO, 'CHECK_SUDOER_HEADER -> ', sudoerToken)
local token = decodeJwtClaim(sudoerToken)
verifyJwtToken(token)
else
ngx.log(ngx.ERR, 'NO AUTH/SUDOER HEADERS!')
ngx.status = 500
ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)
end
while true do
local type, res, err = form:read()