revert refresh token to Sync request
This commit is contained in:
parent
8ff063ead3
commit
c589b4300e
@ -15,6 +15,7 @@ use ManiaControl\Files\AsyncHttpRequest;
|
|||||||
use ManiaControl\Commands\CommandListener;
|
use ManiaControl\Commands\CommandListener;
|
||||||
use ManiaControl\Admin\AuthenticationManager;
|
use ManiaControl\Admin\AuthenticationManager;
|
||||||
use ManiaControl\Callbacks\TimerListener;
|
use ManiaControl\Callbacks\TimerListener;
|
||||||
|
use ManiaControl\Utils\WebReader;
|
||||||
|
|
||||||
if (! class_exists('MatchManagerSuite\MatchManagerCore')) {
|
if (! class_exists('MatchManagerSuite\MatchManagerCore')) {
|
||||||
$this->maniaControl->getChat()->sendErrorToAdmins('MatchManager Core is needed to use MatchManagerGSheet plugin. Install it and restart Maniacontrol');
|
$this->maniaControl->getChat()->sendErrorToAdmins('MatchManager Core is needed to use MatchManagerGSheet plugin. Install it and restart Maniacontrol');
|
||||||
@ -35,7 +36,7 @@ class MatchManagerGSheet implements CallbackListener, TimerListener, CommandLis
|
|||||||
* Constants
|
* Constants
|
||||||
*/
|
*/
|
||||||
const PLUGIN_ID = 156;
|
const PLUGIN_ID = 156;
|
||||||
const PLUGIN_VERSION = 1.0;
|
const PLUGIN_VERSION = 1.1;
|
||||||
const PLUGIN_NAME = 'MatchManager GSheet';
|
const PLUGIN_NAME = 'MatchManager GSheet';
|
||||||
const PLUGIN_AUTHOR = 'Beu';
|
const PLUGIN_AUTHOR = 'Beu';
|
||||||
|
|
||||||
@ -339,30 +340,26 @@ class MatchManagerGSheet implements CallbackListener, TimerListener, CommandLis
|
|||||||
|
|
||||||
if (!empty($refreshtoken) && !empty($expire) && !empty($clientid) && !empty($clientsecret)) {
|
if (!empty($refreshtoken) && !empty($expire) && !empty($clientid) && !empty($clientsecret)) {
|
||||||
if (time() >= $expire) {
|
if (time() >= $expire) {
|
||||||
$asyncHttpRequest = new AsyncHttpRequest($this->maniaControl, 'https://oauth2.googleapis.com/token?grant_type=refresh_token&client_id=' . $clientid . '&client_secret=' . $clientsecret . '&refresh_token=' . $refreshtoken);
|
$response = WebReader::postUrl('https://oauth2.googleapis.com/token?grant_type=refresh_token&client_id=' . $clientid . '&client_secret=' . $clientsecret . '&refresh_token=' . $refreshtoken);
|
||||||
$asyncHttpRequest->setContentType("application/x-www-form-urlencoded");
|
$json = $response->getContent();
|
||||||
$asyncHttpRequest->setCallable(function ($json, $error) {
|
if (!$json) {
|
||||||
if (!$json) {
|
Logger::logError('Impossible to Google API: ' . $json);
|
||||||
Logger::logError('Impossible to Google API: ' . $json);
|
return;
|
||||||
return;
|
}
|
||||||
}
|
$data = json_decode($json);
|
||||||
$data = json_decode($json);
|
if (!$data) {
|
||||||
if (!$data) {
|
Logger::logError('Json parse error: ' . $json);
|
||||||
Logger::logError('Json parse error: ' . $json);
|
return;
|
||||||
return;
|
}
|
||||||
}
|
if (isset($data->access_token)) {
|
||||||
if (isset($data->access_token)) {
|
$this->access_token = $data->access_token;
|
||||||
$this->access_token = $data->access_token;
|
$this->saveSecretSetting("access_token", $data->access_token);
|
||||||
$this->saveSecretSetting("access_token", $data->access_token);
|
$this->saveSecretSetting("expire", time() + $data->expires_in);
|
||||||
$this->saveSecretSetting("expire", time() + $data->expires_in);
|
} elseif (isset($data->error_description)) {
|
||||||
} elseif (isset($data->error_description)) {
|
$this->maniaControl->getChat()->sendErrorToAdmins('Google refused the request: ' . $data->error_description);
|
||||||
$this->maniaControl->getChat()->sendErrorToAdmins('Google refused the request: ' . $data->error_description);
|
} else {
|
||||||
} else {
|
$this->maniaControl->getChat()->sendErrorToAdmins('Unkown error');
|
||||||
$this->maniaControl->getChat()->sendErrorToAdmins('Unkown error');
|
}
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
$asyncHttpRequest->postData(1000);
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user