Merge pull request #13150 from appwrite/fix/oauth2-email-verification

fix(oauth2): derive emailVerification from the provider instead of assuming it
This commit is contained in:
Eldad A. Fux authored and GitHub committed 2026-08-09 07:07:26 +01:00
commit ea174df83b
17 files changed
+51 -45

No files matched your search

+7 -3
View File
@@ -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']);
+2 -3
View File
@@ -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;
}
/**
+9 -1
View File
@@ -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;
}
/**
+2 -3
View File
@@ -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;
}
/**
+2 -3
View File
@@ -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;
}
/**
+2 -3
View File
@@ -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;
}
/**
+2 -3
View File
@@ -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;
}
/**
+2 -1
View File
@@ -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;
}
/**
+2 -3
View File
@@ -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;
}
/**
+2 -3
View File
@@ -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;
}
/**
+2 -3
View File
@@ -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;
}
/**
+2 -3
View File
@@ -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;
}
/**
+2 -3
View File
@@ -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;
}
/**
+2 -3
View File
@@ -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;
}
/**
+4 -1
View File
@@ -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']);
}
/**
+5 -3
View File
@@ -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;
}
/**
+2 -3
View File
@@ -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;
}
/**