mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
Improve GitHub oauth email discovery
This commit is contained in:
@@ -566,6 +566,10 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect')
|
||||
$name = $oauth2->getUserName($accessToken);
|
||||
$email = $oauth2->getUserEmail($accessToken);
|
||||
|
||||
if(empty($email)) {
|
||||
throw new Exception(Exception::USER_UNAUTHORIZED, 'OAuth provider failed to return email.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Is verified is not used yet, since we don't know after an accout is created anymore if it was verified or not.
|
||||
*/
|
||||
|
||||
@@ -183,13 +183,27 @@ class Github extends OAuth2
|
||||
$emails = $this->request('GET', 'https://api.github.com/user/emails', ['Authorization: token ' . \urlencode($accessToken)]);
|
||||
|
||||
$emails = \json_decode($emails, true);
|
||||
|
||||
$verifiedEmail = null;
|
||||
$primaryEmail = null;
|
||||
|
||||
foreach ($emails as $email) {
|
||||
if (isset($email['verified']) && $email['verified'] === true) {
|
||||
$this->user['email'] = $email['email'];
|
||||
$this->user['verified'] = $email['verified'];
|
||||
break;
|
||||
$verifiedEmail = $email;
|
||||
|
||||
if (isset($email['primary']) && $email['primary'] === true) {
|
||||
$primaryEmail = $email;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!empty($primaryEmail)) {
|
||||
$this->user['email'] = $primaryEmail['email'];
|
||||
$this->user['verified'] = $primaryEmail['verified'];
|
||||
} else if(!empty($verifiedEmail)) {
|
||||
$this->user['email'] = $verifiedEmail['email'];
|
||||
$this->user['verified'] = $verifiedEmail['verified'];
|
||||
}
|
||||
}
|
||||
|
||||
return $this->user;
|
||||
|
||||
Reference in New Issue
Block a user