From 3fe98a6f30ef5ed9110014f02c95c55ec015abbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Thu, 3 Feb 2022 11:57:04 +0000 Subject: [PATCH] Code review changes --- app/controllers/api/account.php | 5 +++++ src/Appwrite/Auth/OAuth2.php | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index cd997d3beb..abe642b511 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -1714,6 +1714,11 @@ App::patch('/v1/account/sessions/:sessionId') $appSecret = $project->getAttribute('providers', [])[$provider.'Secret'] ?? '{}'; $className = 'Appwrite\\Auth\\OAuth2\\'.\ucfirst($provider); + + if (!\class_exists($className)) { + throw new Exception('Provider is not supported', 501); + } + $oauth2 = new $className($appId, $appSecret, '', [], []); $oauth2->refreshTokens($refreshToken); diff --git a/src/Appwrite/Auth/OAuth2.php b/src/Appwrite/Auth/OAuth2.php index 9b4c3b9384..4eafba7610 100644 --- a/src/Appwrite/Auth/OAuth2.php +++ b/src/Appwrite/Auth/OAuth2.php @@ -124,7 +124,7 @@ abstract class OAuth2 public function getAccessToken(string $code):string { $tokens = $this->getTokens($code); - return $tokens['access_token']; + return $tokens['access_token'] ?? ''; } /** @@ -135,7 +135,7 @@ abstract class OAuth2 public function getRefreshToken(string $code):string { $tokens = $this->getTokens($code); - return $tokens['refresh_token']; + return $tokens['refresh_token'] ?? ''; } /** @@ -146,7 +146,7 @@ abstract class OAuth2 public function getAccessTokenExpiry(string $code):string { $tokens = $this->getTokens($code); - return $tokens['expires_in']; + return $tokens['expires_in'] ?? ''; } // The parseState function was designed specifically for Amazon OAuth2 Adapter to override.