Skip to content

Commit a222f55

Browse files
committed
refactor: improve JWT validation logging and response handling
1 parent fc1cf70 commit a222f55

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

nginx.conf

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,19 @@ http {
1212
location /api {
1313
content_by_lua_block {
1414
local libjwt = require("resty.libjwt")
15-
local valid, err = libjwt.validate({
16-
["header_token"] = "Authorization",
17-
["jwks_files"] = { "/usr/share/tokens/jwks.json"},
15+
local cjson = require("cjson.safe")
16+
local claim, err = libjwt.validate({
17+
["header_token"] = "Authorization",
18+
["jwks_files"] = { "....", "/usr/share/tokens/jwks.json"},
1819
})
19-
if err ~= "" then
20+
if err and err ~= "" then
21+
ngx.log(ngx.ERR, "JWT Validation Error: " .. err)
2022
return ngx.say(err)
2123
end
22-
if valid then
23-
return ngx.say("OK")
24+
if claim then
25+
local claim_str = cjson.encode(claim) or "Invalid Claim"
26+
ngx.log(ngx.ERR, "JWT Claims: " .. claim_str)
27+
return ngx.say(claim_str)
2428
end
2529
return ngx.say("Unauthorized")
2630
}

0 commit comments

Comments
 (0)