Skip to content

Commit 23f82b5

Browse files
committed
refactor: improve JWKS file handling in validation function
1 parent a09be83 commit 23f82b5

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

lib/resty/libjwt.lua

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,19 @@ function _M.validate( params)
2222
return false, err
2323
end
2424
for i, jwks_file in ipairs(params.jwks_files) do
25-
local jwks = _M.read_file(jwks_file)
26-
if jwks == nil then
27-
return false, "jwks file not found"
25+
local file = _M.read_file(jwks_file)
26+
if file == nil then
27+
goto continue
2828
end
29-
local jwks_set = jwks_c.jwks_create(jwks);
29+
local jwks_set = jwks_c.jwks_create(file);
3030
local jwks_item = jwks_c.jwks_item_get(jwks_set, 0);
3131
local checker = jwks_c.jwt_checker_new();
3232
jwks_c.jwt_checker_setkey(checker, jwks_c.JWT_ALG_RS256, jwks_item);
3333
local result = jwks_c.jwt_checker_verify(checker, token);
3434
if result == 0 then
3535
return true, ""
3636
end
37+
::continue::
3738
end
3839
return false, "token not valid"
3940
end

nginx.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ http {
1414
local libjwt = require("resty.libjwt")
1515
local valid, err = libjwt.validate({
1616
["header_token"] = "Authorization",
17-
["jwks_files"] = {"/usr/share/tokens/jwks.json"},
17+
["jwks_files"] = { "/usr/share/tokens/jwks.json"},
1818
})
1919
if err ~= "" then
2020
return ngx.say(err)

0 commit comments

Comments
 (0)