Skip to content

Commit 398226b

Browse files
authored
Merge pull request #96 from bodewig/filter_token_auth_methods
fiter token_auth_methods by those actually supported
2 parents 3ef95e3 + 9e3e773 commit 398226b

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

lib/resty/openidc.lua

+18-2
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ local pairs = pairs
5656
local type = type
5757
local ngx = ngx
5858

59+
local supported_token_auth_methods = {
60+
client_secret_basic = true,
61+
client_secret_post = true
62+
}
63+
5964
local openidc = {
6065
_VERSION = "1.4.0"
6166
}
@@ -549,6 +554,11 @@ end
549554
-- get the token endpoint authentication method
550555
local function openidc_get_token_auth_method(opts)
551556

557+
if opts.token_endpoint_auth_method ~= nil and not supported_token_auth_methods[opts.token_endpoint_auth_method] then
558+
ngx.log(ngx.ERR, "configured value for token_endpoint_auth_method ("..opts.token_endpoint_auth_method..") is not supported, ignoring it")
559+
opts.token_endpoint_auth_method = nil
560+
end
561+
552562
local result
553563
if opts.discovery.token_endpoint_auth_methods_supported ~= nil then
554564
-- if set check to make sure the discovery data includes the selected client auth method
@@ -566,8 +576,14 @@ local function openidc_get_token_auth_method(opts)
566576
return nil
567577
end
568578
else
569-
result = opts.discovery.token_endpoint_auth_methods_supported[1]
570-
ngx.log(ngx.DEBUG, "no configuration setting for option so select the first method specified by the OP: "..result)
579+
for index, value in ipairs (opts.discovery.token_endpoint_auth_methods_supported) do
580+
ngx.log(ngx.DEBUG, index.." => "..value)
581+
if supported_token_auth_methods[value] then
582+
result = value
583+
ngx.log(ngx.DEBUG, "no configuration setting for option so select the first supported method specified by the OP: "..result)
584+
break
585+
end
586+
end
571587
end
572588
else
573589
result = opts.token_endpoint_auth_method

0 commit comments

Comments
 (0)