Troubleshooting Authorization Failures

Author:
Pili Guerra Arias
Version:
1.0
Language:
Lua, Nginx

Description:Re-uses the X-3scale-debug header to add additional logging to the nginx log to view:

  1. headers sent to 3scale
  2. Actual request made to 3scale, and
  3. Response from 3scale
This snippet should be added inside the authorization location that is failing.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
body_filter_by_lua_block{
        if ngx.req.get_headers()["X-3scale-debug"] == ngx.var.provider_key then
          local resp = ""
          ngx.ctx.buffered = (ngx.ctx.buffered or "") .. string.sub(ngx.arg[1], 1, 1000)
          if ngx.arg[2] then
            resp = ngx.ctx.buffered
          end

          ngx.log(0, ngx.req.raw_header())
          ngx.log(0, resp)
        end
      }
comments powered by Disqus