Skip to content
Snippets Groups Projects
Commit a5610610 authored by Zoltán's avatar Zoltán
Browse files

refresh token segitsegevel access token frissitese

parent db8593e0
Branches
No related tags found
No related merge requests found
...@@ -30,6 +30,8 @@ class AuthSCHClient { ...@@ -30,6 +30,8 @@ class AuthSCHClient {
} else { } else {
// load tokendata from session // load tokendata from session
$this->tokens = unserialize($_SESSION['tokens']); $this->tokens = unserialize($_SESSION['tokens']);
if($this->tokens->lastUpdate + 3600 < time())
$this->reauthenticate();
} }
} else { } else {
$this->tokens = $tokens; $this->tokens = $tokens;
...@@ -96,6 +98,20 @@ class AuthSCHClient { ...@@ -96,6 +98,20 @@ class AuthSCHClient {
} }
private function reauthenticate() {
$data = array(
'grant_type'=>'refresh_token',
'refresh_token'=>$this->tokens->refresh_token,
);
$ch = $this->curlExec("oauth2/token", $data);
$response = json_decode($ch);
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() { public function getData() {
return json_decode(file_get_contents(self::$host . 'api/profile/?access_token=' . $this->tokens->access_token)); return json_decode(file_get_contents(self::$host . 'api/profile/?access_token=' . $this->tokens->access_token));
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment