diff --git a/php/AuthSCHClient.class.php b/php/AuthSCHClient.class.php index ba17aace95932689b8ceb4a07938deb1a9a69017..a27e428027663438566afeca9d2c3fdc52a1ba96 100644 --- a/php/AuthSCHClient.class.php +++ b/php/AuthSCHClient.class.php @@ -43,16 +43,18 @@ class AuthSCHClient { } public function __destruct() { - if(isset($this->tokens)) + if(isset($this->tokens)) { unset ($this->tokens); + } } private function curlExec($urlPart, $data) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, self::$host . $urlPart); curl_setopt($ch, CURLOPT_HEADER, 0); - if($urlPart != "oauth2/resource") + if($urlPart != "oauth2/resource") { curl_setopt($ch, CURLOPT_USERPWD, self::$username . ":" . self::$password); + } curl_setopt($ch, CURLOPT_TIMEOUT, 30); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); @@ -111,15 +113,16 @@ class AuthSCHClient { $ch = $this->curlExec("oauth2/token", $data); $tokens = json_decode($ch); - if($tokens === null || !isset($tokens->access_token) || empty($tokens->access_token)) + if($tokens === null || !isset($tokens->access_token) || empty($tokens->access_token)) { throw new Exception ("invalid token data"); + } $this->tokens->access_token = $tokens->access_token; } public function getData() { $response = @file_get_contents(self::$host . 'api/profile/?access_token=' . $this->tokens->access_token); - if(isset($response) && !empty($response)) { + if(isset($response) && $response !== false && !empty($response)) { $data = json_decode($response); if($data !== null) { return $data; @@ -127,8 +130,9 @@ class AuthSCHClient { throw new Exception('invalid json'); } } else { - if(isset($_SESSION['tokens'])) + if(isset($_SESSION['tokens'])) { unset ($_SESSION['tokens']); + } throw new Exception('invalid response'); } }