From e0e25ea54ba6fe468997a9da5f9f64a58bbc6ac1 Mon Sep 17 00:00:00 2001 From: Lucas Bartholemy Date: Wed, 25 May 2016 17:19:37 +0200 Subject: [PATCH] Fixed GitHub e-mail address lookup --- .../humhub/modules/user/authclient/GitHub.php | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/protected/humhub/modules/user/authclient/GitHub.php b/protected/humhub/modules/user/authclient/GitHub.php index 5d367765b9..c76cf9ff7c 100644 --- a/protected/humhub/modules/user/authclient/GitHub.php +++ b/protected/humhub/modules/user/authclient/GitHub.php @@ -14,6 +14,27 @@ namespace humhub\modules\user\authclient; class GitHub extends \yii\authclient\clients\GitHub { + /** + * @inheritdoc + */ + protected function normalizeUserAttributes($attributes) + { + if (!isset($attributes['email'])) { + $emails = $this->api('user/emails', 'GET'); + + if (is_array($emails)) { + foreach ($emails as $email) { + if ($email['primary'] == 1 && $email['verified'] == 1) { + $attributes['email'] = $email['email']; + break; + } + } + } + } + + return parent::normalizeUserAttributes($attributes); + } + /** * @inheritdoc */