diff --git a/public/lib/filelib.php b/public/lib/filelib.php index 26ee43a09be..b9a0f19eb25 100644 --- a/public/lib/filelib.php +++ b/public/lib/filelib.php @@ -4135,9 +4135,10 @@ class curl { * @param string $url * @param array $params * @param array $options + * @param bool $includeuserpwd Whether to include CURLOPT_USERPWD if not already set * @return ?string */ - public function put($url, $params = array(), $options = array()) { + public function put($url, $params = [], $options = [], $includeuserpwd = true) { $file = ''; $fp = false; if (isset($params['file'])) { @@ -4151,7 +4152,7 @@ class curl { } else { return null; } - if (!isset($this->options['CURLOPT_USERPWD'])) { + if (!isset($this->options['CURLOPT_USERPWD']) && $includeuserpwd) { $this->setopt(array('CURLOPT_USERPWD' => 'anonymous: noreply@moodle.org')); } } else { diff --git a/public/repository/onedrive/lib.php b/public/repository/onedrive/lib.php index f211cb50073..828709923ca 100644 --- a/public/repository/onedrive/lib.php +++ b/public/repository/onedrive/lib.php @@ -792,7 +792,7 @@ class repository_onedrive extends repository { protected function upload_file(\repository_onedrive\rest $service, \curl $curl, \curl $authcurl, $filepath, $mimetype, $parentid, $filename) { // Start an upload session. - // Docs https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/item_createuploadsession link. + // Docs https://learn.microsoft.com/en-us/graph/api/driveitem-createuploadsession?view=graph-rest-1.0 link. $params = ['parentid' => $parentid, 'filename' => urlencode($filename)]; $behaviour = [ 'item' => [ "@microsoft.graph.conflictBehavior" => "rename" ] ]; @@ -813,7 +813,8 @@ class repository_onedrive extends repository { $curlinstance->setHeader('Content-type: ' . $mimetype); $size = filesize($filepath); $curlinstance->setHeader('Content-Range: bytes 0-' . ($size - 1) . '/' . $size); - $response = $curlinstance->put($created->uploadUrl, $options); + // Microsoft does not allow authorization headers for PUT, so we do not include them here. + $response = $curlinstance->put($created->uploadUrl, $options, [], false); // False = do not include auth header. if ($curlinstance->errno == 0) { $response = json_decode($response); }