From c0b057a86bba8ebc8c9c78ee4620db36758d0a59 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Fri, 20 Jan 2023 10:04:47 +0100 Subject: [PATCH] Fixes for PHP 8.1 (#179) undefined --- composer.json | 4 ++++ src/Thybag/Auth/SharePointOnlineAuth.php | 28 ++++++++++++++++++------ 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/composer.json b/composer.json index b7b3bc2..0c0e650 100644 --- a/composer.json +++ b/composer.json @@ -10,6 +10,10 @@ "email": "carl@userbag.co.uk" } ], + "require": { + "php": "^7.1 || ^8.0", + "ext-soap": "*" + }, "autoload": { "psr-0": { "Thybag" : "src/" diff --git a/src/Thybag/Auth/SharePointOnlineAuth.php b/src/Thybag/Auth/SharePointOnlineAuth.php index a99ce6d..df8900d 100644 --- a/src/Thybag/Auth/SharePointOnlineAuth.php +++ b/src/Thybag/Auth/SharePointOnlineAuth.php @@ -13,8 +13,26 @@ class SharePointOnlineAuth extends \SoapClient { // Authentication cookies private $authCookies = false; + private $login; + private $password; + + /** + * Store username+password ourselves since they are private in + * PHP 8.1's SoapClient. + */ + public function __construct($wsdl, $options) { + parent::__construct($wsdl, $options); + + if (isset($options['login'])) { + $this->login = $options['login']; + } + if (isset($options['password'])) { + $this->password = $options['password']; + } + } + // Override do request method - public function __doRequest($request, $location, $action, $version, $one_way = false) { + public function __doRequest($request, $location, $action, $version, $one_way = false): ?string { // Authenticate with SP online in order to get required authentication cookies if (!$this->authCookies) $this->configureAuthCookies($location); @@ -73,17 +91,13 @@ protected function configureAuthCookies($location) { $location = parse_url($location); $endpoint = 'https://'.$location['host']; - // get username & password - $login = $this->{'_login'}; - $password = $this->{'_password'}; - // Create XML security token request - $xml = $this->generateSecurityToken($login, $password, $endpoint); + $xml = $this->generateSecurityToken($this->login, $this->password, $endpoint); // Send request and grab returned xml $result = $this->authCurl("https://login.microsoftonline.com/extSTS.srf", $xml); - + // Extract security token from XML $xml = new \DOMDocument(); $xml->loadXML($result);