Update scopes for calendar API, remove unnecessary logging

This commit is contained in:
2023-01-21 21:04:32 +01:00
parent 0a7a57affa
commit 9c9bf61c7e
4 changed files with 27 additions and 20 deletions

View File

@@ -19,26 +19,25 @@ class GoogleCalendarClient {
$this->client->setAccessType('offline');
$this->client->setRedirectUri(url('/gcalendar/oauth2callback'));
$this->client->addScope(Google_Service_Calendar::CALENDAR);
$this->client->addScope([Google_Service_Calendar::CALENDAR_READONLY , Google_Service_Calendar::CALENDAR_EVENTS_READONLY]);
// Set access toke on client if exist.
$accessToken = Settings::get('access_token');
$accessToken = Settings::get('access_token', []);
if (!empty($accessToken)) {
$this->client->setAccessToken($accessToken);
}
// If there is no previous token or it's expired.
// Ensure valid access token.
if ($tryRefreshToken && $this->client->isAccessTokenExpired()) {
// Refresh the token if possible.
if ($this->client->getRefreshToken()) {
if (!empty($this->client->getRefreshToken())) {
$this->client->fetchAccessTokenWithRefreshToken($this->client->getRefreshToken());
// Save new access token
Settings::set('access_token', $this->client->getAccessToken());
// Merge access token
Settings::set('access_token', array_merge($accessToken, $this->client->getAccessToken()));
} else {
Log::warning('G-Calendar: No valid access token given.');
Log::warning('G-Calendar: No valid refresh token given.');
}
}
}
public function getClient() {
@@ -49,5 +48,4 @@ class GoogleCalendarClient {
return new Google_Service_Calendar($this->client);
}
}
}