Skip to content

Commit 8f2f1c4

Browse files
committed
add functions to read files and extract JWT token from headers in libjwt
1 parent 6d6df51 commit 8f2f1c4

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

lib/resty/libjwt.lua

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
local libjwt_c = loadfile("./jwks_c.lua")
12
local _M = {}
23

34
function _M.get_params(params)
45
local result = {
56
header_token = "Authorization",
7+
jwks_files = {},
68
}
79
if params == nil then
810
return nil, "params is required"
@@ -39,15 +41,38 @@ function _M.split(str, sep)
3941
return result, ""
4042
end
4143

44+
45+
local open = io.open
46+
function _M.read_file(path)
47+
local file = open(path, "rb")
48+
if not file then return nil end
49+
local content = file:read "*a"
50+
file:close()
51+
return content
52+
end
53+
54+
55+
function _M.get_token(headers, field_token)
56+
local auth_header = headers[field_token]
57+
local jwtToken, err = _M.split(auth_header, " ")
58+
if err == "param is required" then
59+
return nil, "token not found"
60+
end
61+
if err ~= "" then
62+
return nil, err
63+
end
64+
if jwtToken[2] == nil then
65+
return nil, "token not found"
66+
end
67+
return jwtToken[2], ""
68+
end
69+
70+
4271
function _M.validate(params)
4372
local params, err = _M.get_params(params)
4473
if err ~= "" then
4574
return nil, err
4675
end
47-
return false, "Not implemented"
4876
end
4977

50-
51-
52-
5378
return _M

0 commit comments

Comments
 (0)