From 552f31dc3709d2452a0fdb5f73d6e7c0d23b9544 Mon Sep 17 00:00:00 2001 From: Jake Dallimore Date: Fri, 14 Oct 2022 13:12:17 +0800 Subject: [PATCH] MDL-76002 enrol_lti: let http_client handle form_params option The lib/lti1p3 library now passes $options['form_params'] instead of $options['body'] when making access token requests. To maintain the 'application/x-www-form-urlencoded' content-type required by OAuth 2.0 (https://www.rfc-editor.org/rfc/rfc6749#section-4.1.3), the client has been changed to convert these array params into a body query string, which matches the behaviour prior to the library upgrade and makes the tool can continue to call tool platform services. Support for $options['body'] remains, as this is still used during service calls. --- enrol/lti/classes/local/ltiadvantage/lib/http_client.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/enrol/lti/classes/local/ltiadvantage/lib/http_client.php b/enrol/lti/classes/local/ltiadvantage/lib/http_client.php index 2762d94abbc..fe9fac862d8 100644 --- a/enrol/lti/classes/local/ltiadvantage/lib/http_client.php +++ b/enrol/lti/classes/local/ltiadvantage/lib/http_client.php @@ -65,7 +65,9 @@ class http_client implements IHttpClient { $this->curlclient->setHeader($headers); } if ($method == 'POST') { - $res = $this->curlclient->post($url, $options['body'] ?? null, ['CURLOPT_HEADER' => 1]); + $body = $options['body'] ?? null; + $body = $body ?? (!empty($options['form_params']) ? http_build_query($options['form_params'], '' , '&') : null); + $res = $this->curlclient->post($url, $body, ['CURLOPT_HEADER' => 1]); } else if ($method == 'GET') { $res = $this->curlclient->get($url, [], ['CURLOPT_HEADER' => 1]); } else {