Skip to content

Commit 5a9ac8e

Browse files
committed
small refactorings
1 parent e3ce0d1 commit 5a9ac8e

File tree

1 file changed

+11
-22
lines changed

1 file changed

+11
-22
lines changed

lib/resty/openidc.lua

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -374,14 +374,13 @@ local function openidc_call_token_endpoint(opts, endpoint, body, auth, endpoint_
374374
end
375375
end
376376

377-
local pass_cookies = opts.pass_cookies or nil
378-
if pass_cookies ~= nil then
379-
local cookies = ngx.req.get_headers()["Cookie"]
380-
if cookies ~= nil then
377+
local pass_cookies = opts.pass_cookies
378+
if pass_cookies then
379+
if ngx.req.get_headers()["Cookie"] then
381380
local t = {}
382381
for cookie_name in string.gmatch(pass_cookies, "%S+") do
383382
local cookie_value = ngx.var["cookie_"..cookie_name]
384-
if cookie_value ~= nil then
383+
if cookie_value then
385384
table.insert(t, cookie_name.."="..cookie_value)
386385
end
387386
end
@@ -1236,39 +1235,29 @@ local function openidc_get_bearer_access_token_from_cookie(opts)
12361235
ngx.log(ngx.DEBUG, "getting bearer access token from Cookie")
12371236

12381237
local accept_token_as = opts.auth_accept_token_as or "header"
1239-
1240-
local default_cookie_name = "PA.global"
1241-
local cookie_name
1242-
1243-
local divider = accept_token_as:find(':')
1244-
1245-
if divider ~= nil then
1246-
cookie_name = accept_token_as:sub(divider+1)
1247-
end
1248-
1249-
if cookie_name == nil then
1250-
cookie_name = default_cookie_name
1238+
if accept_token_as:find("cookie") ~= 1 then
1239+
return nul, "openidc_get_bearer_access_token_from_cookie called but auth_accept_token_as wants "
1240+
.. opts.auth_accept_token_as
12511241
end
1242+
local divider = accept_token_as:find(':')
1243+
local cookie_name = divider and accept_token_as:sub(divider+1) or "PA.global"
12521244

12531245
ngx.log(ngx.DEBUG, "bearer access token from cookie named: "..cookie_name)
12541246

12551247
local cookies = ngx.req.get_headers()["Cookie"]
1256-
1257-
if cookies == nil then
1248+
if not cookies then
12581249
err = "no Cookie header found"
12591250
ngx.log(ngx.ERR, err)
12601251
return nil, err
12611252
end
12621253

12631254
local cookie_value = ngx.var["cookie_"..cookie_name]
1264-
if cookie_value == nil then
1255+
if not cookie_value then
12651256
err = "no Cookie "..cookie_name.." found"
12661257
ngx.log(ngx.ERR, err)
1267-
12681258
end
12691259

12701260
return cookie_value, err
1271-
12721261
end
12731262

12741263

0 commit comments

Comments
 (0)