diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 7e2b650c6a..35ebf065e0 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -1807,8 +1807,8 @@ Http::get('/v1/account/sessions/oauth2/:provider/redirect') Permission::delete(Role::user($userId)), ], 'email' => $email, - 'emailVerification' => true, - 'status' => true, // Email should already be authenticated by OAuth2 provider + 'emailVerification' => $isVerified, // Trust the provider's userinfo claim, not the mere fact an email was returned + 'status' => true, 'password' => null, 'hash' => $proofForPassword->getHash()->getName(), 'hashOptions' => $proofForPassword->getHash()->getOptions(), @@ -1866,6 +1866,8 @@ Http::get('/v1/account/sessions/oauth2/:provider/redirect') 'emailIsFree' => null, ]; + $isVerified = $oauth2->isEmailVerified($accessToken); + try { $parsedEmail = new Email($providerEmail); $canonical = $parsedEmail->getCanonical(); @@ -1874,7 +1876,7 @@ Http::get('/v1/account/sessions/oauth2/:provider/redirect') || ($plan['supportsCanonicalEmailValidation'] ?? false) ) && ($project->getAttribute('auths', [])['canonicalEmails'] ?? false) - && $oauth2->isEmailVerified($accessToken); + && $isVerified; $email = $canonicalize ? $canonical : $providerEmail; $emails = array_values(array_unique([$email, $providerEmail])); $emailMetadata = [ @@ -1913,6 +1915,8 @@ Http::get('/v1/account/sessions/oauth2/:provider/redirect') } $user->setAttribute('email', $email); + // Never downgrade an already-verified user; only ever promote to verified + $user->setAttribute('emailVerification', $user->getAttribute('emailVerification', false) || $isVerified); $user->setAttribute('emailCanonical', $emailMetadata['emailCanonical']); $user->setAttribute('emailIsCanonical', $emailMetadata['emailIsCanonical']); $user->setAttribute('emailIsCorporate', $emailMetadata['emailIsCorporate']); diff --git a/src/Appwrite/Auth/OAuth2/Amazon.php b/src/Appwrite/Auth/OAuth2/Amazon.php index 2fa3f4cfe9..7a7f1b3e9d 100644 --- a/src/Appwrite/Auth/OAuth2/Amazon.php +++ b/src/Appwrite/Auth/OAuth2/Amazon.php @@ -149,9 +149,8 @@ class Amazon extends OAuth2 */ public function isEmailVerified(string $accessToken): bool { - $email = $this->getUserEmail($accessToken); - - return !empty($email); + // Provider exposes no email verification signal, so treat as unverified until one is confirmed + return false; } /** diff --git a/src/Appwrite/Auth/OAuth2/Bitly.php b/src/Appwrite/Auth/OAuth2/Bitly.php index 290876a8cb..e6f062e086 100644 --- a/src/Appwrite/Auth/OAuth2/Bitly.php +++ b/src/Appwrite/Auth/OAuth2/Bitly.php @@ -157,7 +157,15 @@ class Bitly extends OAuth2 */ public function isEmailVerified(string $accessToken): bool { - return true; + $user = $this->getUser($accessToken); + + foreach ($user['emails'] ?? [] as $email) { + if (($email['is_verified'] ?? false) === true) { + return true; + } + } + + return false; } /** diff --git a/src/Appwrite/Auth/OAuth2/Box.php b/src/Appwrite/Auth/OAuth2/Box.php index e88c165833..7a15ab325f 100644 --- a/src/Appwrite/Auth/OAuth2/Box.php +++ b/src/Appwrite/Auth/OAuth2/Box.php @@ -150,9 +150,8 @@ class Box extends OAuth2 */ public function isEmailVerified(string $accessToken): bool { - $email = $this->getUserEmail($accessToken); - - return !empty($email); + // Provider exposes no email verification signal, so treat as unverified until one is confirmed + return false; } /** diff --git a/src/Appwrite/Auth/OAuth2/Etsy.php b/src/Appwrite/Auth/OAuth2/Etsy.php index c878945740..3a6e66773f 100644 --- a/src/Appwrite/Auth/OAuth2/Etsy.php +++ b/src/Appwrite/Auth/OAuth2/Etsy.php @@ -158,9 +158,8 @@ class Etsy extends OAuth2 */ public function isEmailVerified(string $accessToken): bool { - $email = $this->getUserEmail($accessToken); - - return !empty($email); + // Provider exposes no email verification signal, so treat as unverified until one is confirmed + return false; } /** diff --git a/src/Appwrite/Auth/OAuth2/Facebook.php b/src/Appwrite/Auth/OAuth2/Facebook.php index 90fe8e7388..ab1842a80e 100644 --- a/src/Appwrite/Auth/OAuth2/Facebook.php +++ b/src/Appwrite/Auth/OAuth2/Facebook.php @@ -131,9 +131,8 @@ class Facebook extends OAuth2 */ public function isEmailVerified(string $accessToken): bool { - $email = $this->getUserEmail($accessToken); - - return !empty($email); + // Provider exposes no email verification signal, so treat as unverified until one is confirmed + return false; } /** diff --git a/src/Appwrite/Auth/OAuth2/Figma.php b/src/Appwrite/Auth/OAuth2/Figma.php index b5e53cbed4..da29312641 100644 --- a/src/Appwrite/Auth/OAuth2/Figma.php +++ b/src/Appwrite/Auth/OAuth2/Figma.php @@ -139,9 +139,8 @@ class Figma extends OAuth2 */ public function isEmailVerified(string $accessToken): bool { - $email = $this->getUserEmail($accessToken); - - return !empty($email); + // Provider exposes no email verification signal, so treat as unverified until one is confirmed + return false; } /** diff --git a/src/Appwrite/Auth/OAuth2/Kick.php b/src/Appwrite/Auth/OAuth2/Kick.php index bf7ff7930d..652bd10efe 100644 --- a/src/Appwrite/Auth/OAuth2/Kick.php +++ b/src/Appwrite/Auth/OAuth2/Kick.php @@ -147,7 +147,8 @@ class Kick extends OAuth2 */ public function isEmailVerified(string $accessToken): bool { - return !empty($this->getUserEmail($accessToken)); + // Provider exposes no email verification signal, so treat as unverified until one is confirmed + return false; } /** diff --git a/src/Appwrite/Auth/OAuth2/Microsoft.php b/src/Appwrite/Auth/OAuth2/Microsoft.php index 19966ec1ac..0d89eeb718 100644 --- a/src/Appwrite/Auth/OAuth2/Microsoft.php +++ b/src/Appwrite/Auth/OAuth2/Microsoft.php @@ -147,9 +147,8 @@ class Microsoft extends OAuth2 */ public function isEmailVerified(string $accessToken): bool { - $email = $this->getUserEmail($accessToken); - - return !empty($email); + // Microsoft explicitly does not verify emails in Graph /me, so treat as unverified until one is confirmed + return false; } /** diff --git a/src/Appwrite/Auth/OAuth2/Notion.php b/src/Appwrite/Auth/OAuth2/Notion.php index c2f1ee98e4..124c09e599 100644 --- a/src/Appwrite/Auth/OAuth2/Notion.php +++ b/src/Appwrite/Auth/OAuth2/Notion.php @@ -137,9 +137,8 @@ class Notion extends OAuth2 */ public function isEmailVerified(string $accessToken): bool { - $email = $this->getUserEmail($accessToken); - - return !empty($email); + // Provider exposes no email verification signal, so treat as unverified until one is confirmed + return false; } /** diff --git a/src/Appwrite/Auth/OAuth2/Slack.php b/src/Appwrite/Auth/OAuth2/Slack.php index 9c87e45ed6..fac80e9aad 100644 --- a/src/Appwrite/Auth/OAuth2/Slack.php +++ b/src/Appwrite/Auth/OAuth2/Slack.php @@ -131,9 +131,8 @@ class Slack extends OAuth2 */ public function isEmailVerified(string $accessToken): bool { - $email = $this->getUserEmail($accessToken); - - return !empty($email); + // email_verified lives on openid.connect.userInfo, not users.identity; unverified is the safe default until we migrate + return false; } /** diff --git a/src/Appwrite/Auth/OAuth2/Stripe.php b/src/Appwrite/Auth/OAuth2/Stripe.php index 9d1c9206ad..e5fb530d70 100644 --- a/src/Appwrite/Auth/OAuth2/Stripe.php +++ b/src/Appwrite/Auth/OAuth2/Stripe.php @@ -146,9 +146,8 @@ class Stripe extends OAuth2 */ public function isEmailVerified(string $accessToken): bool { - $email = $this->getUserEmail($accessToken); - - return !empty($email); + // Provider exposes no email verification signal, so treat as unverified until one is confirmed + return false; } /** diff --git a/src/Appwrite/Auth/OAuth2/Tradeshift.php b/src/Appwrite/Auth/OAuth2/Tradeshift.php index 8d0bfa8784..16d72821bf 100644 --- a/src/Appwrite/Auth/OAuth2/Tradeshift.php +++ b/src/Appwrite/Auth/OAuth2/Tradeshift.php @@ -154,9 +154,8 @@ class Tradeshift extends OAuth2 */ public function isEmailVerified(string $accessToken): bool { - $email = $this->getUser($accessToken); - - return !empty($email); + // Provider exposes no email verification signal, so treat as unverified until one is confirmed + return false; } /** diff --git a/src/Appwrite/Auth/OAuth2/Twitch.php b/src/Appwrite/Auth/OAuth2/Twitch.php index ed73054c31..8f4ab1a661 100644 --- a/src/Appwrite/Auth/OAuth2/Twitch.php +++ b/src/Appwrite/Auth/OAuth2/Twitch.php @@ -144,9 +144,8 @@ class Twitch extends OAuth2 */ public function isEmailVerified(string $accessToken): bool { - $email = $this->getUserEmail($accessToken); - - return !empty($email); + // email_verified lives on the OIDC userinfo endpoint, not Helix /users; unverified is the safe default until we migrate + return false; } /** diff --git a/src/Appwrite/Auth/OAuth2/X.php b/src/Appwrite/Auth/OAuth2/X.php index c0789fe343..f6ffe5e972 100644 --- a/src/Appwrite/Auth/OAuth2/X.php +++ b/src/Appwrite/Auth/OAuth2/X.php @@ -142,7 +142,10 @@ class X extends OAuth2 */ public function isEmailVerified(string $accessToken): bool { - return !empty($this->getUserEmail($accessToken)); + // X only populates confirmed_email once the address is confirmed, so its presence is the verification signal + $user = $this->getUser($accessToken); + + return !empty($user['data']['confirmed_email']); } /** diff --git a/src/Appwrite/Auth/OAuth2/Yahoo.php b/src/Appwrite/Auth/OAuth2/Yahoo.php index 1a6c6b860d..21ecd9a04d 100644 --- a/src/Appwrite/Auth/OAuth2/Yahoo.php +++ b/src/Appwrite/Auth/OAuth2/Yahoo.php @@ -156,7 +156,9 @@ class Yahoo extends OAuth2 /** * Check if the OAuth email is verified * - * If present, the email is verified. This was verfied through a manual Yahoo sign up process + * Yahoo is an OpenID Connect provider and advertises the `email_verified` + * claim on its userinfo endpoint, so use that instead of merely assuming a + * returned address is confirmed. * * @param string $accessToken * @@ -164,9 +166,9 @@ class Yahoo extends OAuth2 */ public function isEmailVerified(string $accessToken): bool { - $email = $this->getUserEmail($accessToken); + $user = $this->getUser($accessToken); - return !empty($email); + return $user['email_verified'] ?? false; } /** diff --git a/src/Appwrite/Auth/OAuth2/Yammer.php b/src/Appwrite/Auth/OAuth2/Yammer.php index 9e1827bc58..0bbe20861f 100644 --- a/src/Appwrite/Auth/OAuth2/Yammer.php +++ b/src/Appwrite/Auth/OAuth2/Yammer.php @@ -133,9 +133,8 @@ class Yammer extends OAuth2 */ public function isEmailVerified(string $accessToken): bool { - $email = $this->getUserEmail($accessToken); - - return !empty($email); + // Provider exposes no email verification signal, so treat as unverified until one is confirmed + return false; } /**