@@ -72,26 +72,7 @@ function _M.get_token(headers, field_token)
7272 return jwtToken [2 ], " "
7373end
7474
75- function _M .validate_claims (validate_claims , claims )
76- if not validate_claims then
77- return " "
78- end
79-
80- if _M .is_array (validate_claims ) then
81- local errors = {}
82- for i , v in ipairs (validate_claims ) do
83-
84- local result = _M .validate_claims (v , claims )
85- if result == " " then
86- return " "
87- end
88-
89- table.insert (errors , " validate_claims constraint number " .. i .. " : " .. result )
90- end
91-
92- return table.concat (errors , " OR " )
93- end
94-
75+ local function validate_claims_inner (validate_claims , claims )
9576 for claim_name , validation in pairs (validate_claims ) do
9677 local claim_value = claims [claim_name ]
9778 if claim_value == nil then
@@ -123,13 +104,44 @@ function _M.validate_claims(validate_claims, claims)
123104 return " "
124105end
125106
126- function _M .is_array (t )
107+ local function is_array_of_tables (t )
108+ if type (t ) ~= " table" then
109+ return false
110+ end
111+
127112 local i = 0
128113 for _ in pairs (t ) do
129114 i = i + 1
130- if t [i ] == nil then return false end
115+ if t [i ] == nil then
116+ return false
117+ end
118+
119+ if type (t [i ]) ~= " table" then
120+ return false
121+ end
122+
131123 end
132124 return true
133125end
134126
127+ function _M .validate_claims (validate_claims , claims )
128+ if not validate_claims then return " " end
129+
130+ if is_array_of_tables (validate_claims ) then
131+ local errors = {}
132+ for i , v in ipairs (validate_claims ) do
133+
134+ local result = validate_claims_inner (v , claims )
135+ if result == " " then return " " end
136+
137+ table.insert (errors , " validate_claims constraint number " .. i ..
138+ " : " .. result )
139+ end
140+
141+ return table.concat (errors , " OR " )
142+ end
143+
144+ return validate_claims_inner (validate_claims , claims )
145+ end
146+
135147return _M
0 commit comments