From e2db8faaf3144197945f141408135581b6e05a8b Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Thu, 5 May 2022 20:07:27 +0400 Subject: [PATCH] feat: added check for Google OAuth --- src/Appwrite/Auth/OAuth2/Google.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Appwrite/Auth/OAuth2/Google.php b/src/Appwrite/Auth/OAuth2/Google.php index bdc3b42adb..2c78e63b5e 100644 --- a/src/Appwrite/Auth/OAuth2/Google.php +++ b/src/Appwrite/Auth/OAuth2/Google.php @@ -140,12 +140,20 @@ class Google extends OAuth2 /** * Check if the OAuth email is verified * + * @link https://www.oauth.com/oauth2-servers/signing-in-with-google/verifying-the-user-info/ + * * @param $accessToken * * @return bool */ public function isEmailVerified(string $accessToken): bool { + $user = $this->getUser($accessToken); + + if (isset($user['email_verified']) && $user['email_verified'] === true) { + return true; + } + return false; } @@ -173,7 +181,7 @@ class Google extends OAuth2 protected function getUser(string $accessToken): array { if (empty($this->user)) { - $user = $this->request('GET', 'https://www.googleapis.com/oauth2/v2/userinfo?access_token='.\urlencode($accessToken)); + $user = $this->request('GET', 'https://www.googleapis.com/oauth2/v3/userinfo?access_token='.\urlencode($accessToken)); $this->user = \json_decode($user, true); }