From 63a50990afe6be64a4f8c4c729493e4e7c501732 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n?= <Zoltán@zolij-pc.lan> Date: Fri, 18 Jul 2014 10:34:49 +0200 Subject: [PATCH] refresh token bug fixed destructor added getdata() response error handling --- php/AuthSCHClient.class.php | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/php/AuthSCHClient.class.php b/php/AuthSCHClient.class.php index 8846680..ba17aac 100644 --- a/php/AuthSCHClient.class.php +++ b/php/AuthSCHClient.class.php @@ -43,7 +43,8 @@ class AuthSCHClient { } public function __destruct() { - + if(isset($this->tokens)) + unset ($this->tokens); } private function curlExec($urlPart, $data) { @@ -109,7 +110,7 @@ class AuthSCHClient { ); $ch = $this->curlExec("oauth2/token", $data); - $response = json_decode($ch); + $tokens = json_decode($ch); if($tokens === null || !isset($tokens->access_token) || empty($tokens->access_token)) throw new Exception ("invalid token data"); @@ -117,7 +118,19 @@ class AuthSCHClient { } public function getData() { - return json_decode(file_get_contents(self::$host . 'api/profile/?access_token=' . $this->tokens->access_token)); + $response = @file_get_contents(self::$host . 'api/profile/?access_token=' . $this->tokens->access_token); + if(isset($response) && !empty($response)) { + $data = json_decode($response); + if($data !== null) { + return $data; + } else { + throw new Exception('invalid json'); + } + } else { + if(isset($_SESSION['tokens'])) + unset ($_SESSION['tokens']); + throw new Exception('invalid response'); + } } } -- GitLab