Получать электронную почту пользователя от Yahoo, когда пользователь входит в приложение Yahoo - PullRequest
1 голос
/ 23 марта 2019

Есть ли способ получить адрес электронной почты пользователя. Я использую гибридную аутентификацию. Логин работает, адрес электронной почты не получен, получен только идентификатор пользователя, отображаемое имя и отображаемое изображение. Есть ли способ получить доступ к адресу электронной почты пользователя, Все работает нормально, кроме. Ответ дает пустое письмо

class Yahoo extends OAuth2
 {
   protected $scope = 'sdct-r';
   protected $apiBaseUrl = 'https://social.yahooapis.com/v1/';
   protected $authorizeUrl = 'https://api.login.yahoo.com/oauth2/request_auth';
   protected $accessTokenUrl = 'https://api.login.yahoo.com/oauth2/get_token';
   protected $apiDocumentation = 'https://developer.yahoo.com/oauth2/guide/';
   protected $userId = null;
   protected function initialize()
    {
      parent::initialize();
      $this->tokenExchangeHeaders = [
        'Authorization' => 'Basic ' . base64_encode($this->clientId .  ':' . $this->clientSecret) ]; }
  protected function getCurrentUserId()
     {
      if ($this->userId) {
        return $this->userId;
     }
     $response = $this->apiRequest('me/guid', 'GET', [ 'format' => 'json']);
     $data = new Data\Collection($response);
    if (! $data->filter('guid')->exists('value')) {
        throw new UnexpectedApiResponseException('Provider API returned an unexpected response.');
    }
    return $this->userId =  $data->filter('guid')->get('value');
}
public function getUserProfile()
{
    // Retrieve current user guid if needed
    $this->getCurrentUserId();

    $response = $this->apiRequest('user/'  . $this->userId . '/profile', 'GET', [ 'format' => 'json']);

    $data = new Data\Collection($response);

    if (! $data->exists('profile')) {
        throw new UnexpectedApiResponseException('Provider API returned an unexpected response.');
    }

    $userProfile = new User\Profile();

    $data = $data->filter('profile');

    $userProfile->identifier  = $data->get('guid');
    $userProfile->firstName   = $data->get('givenName');
    $userProfile->lastName    = $data->get('familyName');
    $userProfile->displayName = $data->get('nickname');
    $userProfile->photoURL    = $data->filter('image')->get('imageUrl');
    $userProfile->profileURL  = $data->get('profileUrl');
    $userProfile->language    = $data->get('lang');
    $userProfile->address     = $data->get('location');


    if ('F' == $data->get('gender')) {
        $userProfile->gender = 'female';
    } elseif ('M' == $data->get('gender')) {
        $userProfile->gender = 'male';
    }

    // I ain't getting no emails on my tests. go figures..
    foreach ($data->filter('emails')->toArray() as $item) {
        if ($item->primary) {
          $userProfile->email         = $item->handle;
          $userProfile->emailVerified = $item->handle;
        }
    }

    return $userProfile;
}

}

1 Ответ

0 голосов
/ 26 марта 2019

из руководства Yahoo :

Область расширенного профиля sdpp-w, в дополнение к приведенным выше утверждениям, также возвращает следующие утверждения:

email - идентификатор электронной почты пользователя
email_verified - логический флаг, сообщающий клиентам, был ли указанный адрес электронной почты проверен Yahoo.

Пожалуйста, обновите Hybridauth до 3.0-rc.10 , которая исправила эту проблему для провайдера Yahoo.

См. Оригинальный PR с исправлением: https://github.com/hybridauth/hybridauth/pull/986

...