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
No related branches found
No related tags found
No related merge requests found
......@@ -30,6 +30,8 @@ class AuthSCHClient {
} else {
// load tokendata from session
$this->tokens = unserialize($_SESSION['tokens']);
if($this->tokens->lastUpdate + 3600 < time())
$this->reauthenticate();
}
} else {
$this->tokens = $tokens;
......@@ -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() {
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