Should note in the documentation or the examples that it is safer to clear the X-Auth-UserId header before trying to authenticate the request, something like:
location /secure {
access_by_lua '
ngx.req.clear_header("X-Auth-UserId")
local jwt = require("nginx-jwt")
jwt.auth()
';
}
Also noticed that the header is being set on the response not the request, shouldn't it be the other way around? So that backends get the authenticated subject. Currently, we have this in our nginx-jwt.lua:
-- write the X-Auth-UserId header
-- ngx.header["X-Auth-UserId"] = jwt_obj.payload.sub
ngx.req.set_header("X-Auth-UserId", jwt_obj.payload.sub)