auth.prod.lua 1.1 KB

123456789101112131415161718192021222324252627282930
  1. local function forbidden()
  2. ngx.status = ngx.HTTP_UNAUTHORIZED
  3. ngx.header.content_type = "application/json; charset=utf-8"
  4. ngx.say("{\"status\": 401, \"message\": \"Unauthorized\", \"error\": 1}")
  5. return ngx.exit(ngx.HTTP_OK)
  6. end
  7. local function simple_debug(msg)
  8. ngx.say(msg)
  9. return ngx.exit(ngx.HTTP_OK)
  10. end
  11. local upload_user = ngx.req.get_headers()["UPLOAD-SERVER-USER"]
  12. local upload_token = ngx.req.get_headers()["UPLOAD-SERVER-TOKEN"]
  13. local upload_date = ngx.req.get_headers()["UPLOAD-SERVER-DATE"]
  14. local upload_notify_url = ngx.req.get_headers()["UPLOAD-SERVER-NOTIFY-URL"]
  15. local secretkey='k4Ao7KWVbvg3Z2L6KLwN9OoDjQL5SioJffIPoODATxCynuEVEAt0278kg7r9FHiS'
  16. local date = os.date("%Y%m%d%H")
  17. if upload_user == nil or upload_token == nil then
  18. return forbidden()
  19. end
  20. if upload_notify_url == nil then
  21. upload_notify_url = ''
  22. end
  23. if upload_date == nil then
  24. upload_date = date
  25. end
  26. local string = 'uid:' .. tostring(upload_user) .. '&secretkey:' .. tostring(secretkey) .. '&datetime:' .. tostring(upload_date) .. '&notifyurl:' .. tostring(upload_notify_url)
  27. local token = ngx.md5(string)
  28. if token ~= upload_token then
  29. return forbidden()
  30. end