From 405cc14d0018b863e7c7c9947ce691769cdf1677 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=98=BF=E7=94=B7?= Date: Sun, 28 Nov 2021 15:40:07 +0800 Subject: [PATCH] fix --- music-room-test.conf | 2 +- upload.lua | 46 ++++++++++++++++++-------------------------- 2 files changed, 20 insertions(+), 28 deletions(-) diff --git a/music-room-test.conf b/music-room-test.conf index a6e0396..1218966 100644 --- a/music-room-test.conf +++ b/music-room-test.conf @@ -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"; diff --git a/upload.lua b/upload.lua index e90d422..8976ef0 100644 --- a/upload.lua +++ b/upload.lua @@ -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()