Skip to content

Commit 8f35802

Browse files
committed
improve error message if signing key is missing, see #238
Signed-off-by: Stefan Bodewig <[email protected]>
1 parent 7e0cebd commit 8f35802

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

lib/resty/openidc.lua

+5-2
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,10 @@ function openidc.call_token_endpoint(opts, endpoint, body, auth, endpoint_name,
416416
log(DEBUG, "client_secret_post: client_id and client_secret being sent in POST body")
417417

418418
elseif auth == "private_key_jwt" or auth == "client_secret_jwt" then
419+
local key = auth == "private_key_jwt" and opts.client_rsa_private_key or opts.client_secret
420+
if not key then
421+
return nil, "Can't use " .. auth .. " without a key."
422+
end
419423
body.client_id = opts.client_id
420424
body.client_assertion_type = "urn:ietf:params:oauth:client-assertion-type:jwt-bearer"
421425
local now = ngx.time()
@@ -438,8 +442,7 @@ function openidc.call_token_endpoint(opts, endpoint, body, auth, endpoint_name,
438442
end
439443

440444
local r_jwt = require("resty.jwt")
441-
body.client_assertion = r_jwt:sign(auth == "private_key_jwt" and opts.client_rsa_private_key or opts.client_secret,
442-
assertion)
445+
body.client_assertion = r_jwt:sign(key, assertion)
443446
log(DEBUG, auth .. ": client_id, client_assertion_type and client_assertion being sent in POST body")
444447
end
445448
end

0 commit comments

Comments
 (0)