@@ -66,11 +66,21 @@ local DEBUG = ngx.DEBUG
66
66
local ERROR = ngx .ERR
67
67
local WARN = ngx .WARN
68
68
69
+ local function token_auth_method_precondition (method , required_field )
70
+ return function (opts )
71
+ if not opts [required_field ] then
72
+ ngx .log (ngx .DEBUG , " Can't use " .. method .. " without opts." .. required_field )
73
+ return false
74
+ end
75
+ return true
76
+ end
77
+ end
78
+
69
79
local supported_token_auth_methods = {
70
80
client_secret_basic = true ,
71
81
client_secret_post = true ,
72
- private_key_jwt = true ,
73
- client_secret_jwt = true
82
+ private_key_jwt = token_auth_method_precondition ( ' private_key_jwt ' , ' client_rsa_private_key ' ) ,
83
+ client_secret_jwt = token_auth_method_precondition ( ' client_secret_jwt ' , ' client_secret ' )
74
84
}
75
85
76
86
local openidc = {
@@ -582,10 +592,15 @@ local function openidc_ensure_discovered_data(opts)
582
592
return err
583
593
end
584
594
595
+ local function can_use_token_auth_method (method , opts )
596
+ local supported = supported_token_auth_methods [method ]
597
+ return supported and (type (supported ) ~= ' function' or supported (opts ))
598
+ end
599
+
585
600
-- get the token endpoint authentication method
586
601
local function openidc_get_token_auth_method (opts )
587
602
588
- if opts .token_endpoint_auth_method ~= nil and not supported_token_auth_methods [ opts .token_endpoint_auth_method ] then
603
+ if opts .token_endpoint_auth_method ~= nil and not can_use_token_auth_method ( opts .token_endpoint_auth_method , opts ) then
589
604
log (ERROR , " configured value for token_endpoint_auth_method (" .. opts .token_endpoint_auth_method .. " ) is not supported, ignoring it" )
590
605
opts .token_endpoint_auth_method = nil
591
606
end
@@ -609,7 +624,7 @@ local function openidc_get_token_auth_method(opts)
609
624
else
610
625
for index , value in ipairs (opts .discovery .token_endpoint_auth_methods_supported ) do
611
626
log (DEBUG , index .. " => " .. value )
612
- if supported_token_auth_methods [ value ] then
627
+ if can_use_token_auth_method ( value , opts ) then
613
628
result = value
614
629
log (DEBUG , " no configuration setting for option so select the first supported method specified by the OP: " .. result )
615
630
break
0 commit comments