@@ -509,39 +509,6 @@ function openidc.call_token_endpoint(opts, endpoint, body, auth, endpoint_name,
509509 return openidc_parse_json_response (res , ignore_body_on_success )
510510end
511511
512- -- make a call to the userinfo endpoint
513- function openidc .call_userinfo_endpoint (opts , access_token )
514- if not opts .discovery .userinfo_endpoint then
515- log (DEBUG , " no userinfo endpoint supplied" )
516- return nil , nil
517- end
518-
519- local headers = {
520- [" Authorization" ] = " Bearer " .. access_token ,
521- }
522-
523- log (DEBUG , " authorization header '" .. headers .Authorization .. " '" )
524-
525- local httpc = http .new ()
526- openidc_configure_timeouts (httpc , opts .timeout )
527- openidc_configure_proxy (httpc , opts .proxy_opts )
528- local res , err = httpc :request_uri (opts .discovery .userinfo_endpoint ,
529- decorate_request (opts .http_request_decorator , {
530- headers = headers ,
531- ssl_verify = (opts .ssl_verify ~= " no" ),
532- keepalive = (opts .keepalive ~= " no" )
533- }))
534- if not res then
535- err = " accessing (" .. opts .discovery .userinfo_endpoint .. " ) failed: " .. err
536- return nil , err
537- end
538-
539- log (DEBUG , " userinfo response: " , res .body )
540-
541- -- parse the response from the user info endpoint
542- return openidc_parse_json_response (res )
543- end
544-
545512-- computes access_token expires_in value (in seconds)
546513local function openidc_access_token_expires_in (opts , expires_in )
547514 return (expires_in or opts .access_token_expires_in or 3600 ) - 1 - (opts .access_token_expires_leeway or 0 )
@@ -614,6 +581,40 @@ local function openidc_ensure_discovered_data(opts)
614581 return err
615582end
616583
584+ -- make a call to the userinfo endpoint
585+ function openidc .call_userinfo_endpoint (opts , access_token )
586+ openidc_ensure_discovered_data (opts )
587+ if not opts .discovery .userinfo_endpoint then
588+ log (DEBUG , " no userinfo endpoint supplied" )
589+ return nil , nil
590+ end
591+
592+ local headers = {
593+ [" Authorization" ] = " Bearer " .. access_token ,
594+ }
595+
596+ log (DEBUG , " authorization header '" .. headers .Authorization .. " '" )
597+
598+ local httpc = http .new ()
599+ openidc_configure_timeouts (httpc , opts .timeout )
600+ openidc_configure_proxy (httpc , opts .proxy_opts )
601+ local res , err = httpc :request_uri (opts .discovery .userinfo_endpoint ,
602+ decorate_request (opts .http_request_decorator , {
603+ headers = headers ,
604+ ssl_verify = (opts .ssl_verify ~= " no" ),
605+ keepalive = (opts .keepalive ~= " no" )
606+ }))
607+ if not res then
608+ err = " accessing (" .. opts .discovery .userinfo_endpoint .. " ) failed: " .. err
609+ return nil , err
610+ end
611+
612+ log (DEBUG , " userinfo response: " , res .body )
613+
614+ -- parse the response from the user info endpoint
615+ return openidc_parse_json_response (res )
616+ end
617+
617618local function can_use_token_auth_method (method , opts )
618619 local supported = supported_token_auth_methods [method ]
619620 return supported and (type (supported ) ~= ' function' or supported (opts ))
0 commit comments