Yandex.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace Hybridauth\Provider;
  3. use Hybridauth\Adapter\OAuth2;
  4. use Hybridauth\Exception\Exception;
  5. use Hybridauth\Data\Collection;
  6. use Hybridauth\User\Profile;
  7. class Yandex extends OAuth2
  8. {
  9. protected $apiBaseUrl = 'https://login.yandex.ru/info';
  10. protected $authorizeUrl = 'https://oauth.yandex.ru/authorize';
  11. protected $accessTokenUrl = 'https://oauth.yandex.ru/token';
  12. /**
  13. * @return bool|Profile
  14. * @throws Exception
  15. * @throws \Hybridauth\Exception\HttpClientFailureException
  16. * @throws \Hybridauth\Exception\HttpRequestFailedException
  17. * @throws \Hybridauth\Exception\InvalidAccessTokenException
  18. */
  19. function getUserProfile()
  20. {
  21. $data = new Collection($this->apiRequest('', 'GET'));
  22. if (!$data->exists('id')) {
  23. throw new Exception('User profile request failed! ModxPro returned an invalid response.');
  24. }
  25. $userProfile = new Profile();
  26. $userProfile->identifier = $data->get('id');
  27. $userProfile->firstName = $data->get('real_name');
  28. $userProfile->lastName = $data->get('family_name');
  29. $userProfile->displayName = $data->get('display_name');
  30. $userProfile->photoURL = 'http://upics.yandex.net/' . $userProfile->identifier . '/normal';
  31. $userProfile->profileURL = '';
  32. $userProfile->gender = (int)$data->get('sex') == 'female';
  33. $userProfile->email =
  34. $userProfile->emailVerified = $data->get('default_email');
  35. if ($dob = $data->get('birthday')) {
  36. list($userProfile->birthYear, $userProfile->birthMonth, $userProfile->birthDay) = explode('-', $dob);
  37. }
  38. return $userProfile;
  39. }
  40. }