ModxPro.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 ModxPro extends OAuth2
  8. {
  9. protected $apiBaseUrl = 'https://id.modx.pro/oauth2';
  10. protected $authorizeUrl = 'https://id.modx.pro/oauth2/auth';
  11. protected $accessTokenUrl = 'https://id.modx.pro/oauth2/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('profile', 'POST'));
  22. if (!$data->exists('identifier')) {
  23. throw new Exception('User profile request failed! ModxPro returned an invalid response.');
  24. }
  25. $userProfile = new Profile();
  26. $userProfile->identifier = $data->get('identifier');
  27. $userProfile->email = $data->get('email');
  28. $userProfile->displayName = $data->get('displayName');
  29. $userProfile->photoURL = $data->get('photoURL');
  30. $userProfile->webSiteURL = $data->get('webSiteURL');
  31. $userProfile->profileURL = $data->get('profileUrl');
  32. $userProfile->phone = $data->get('phone');
  33. $userProfile->address = $data->get('address');
  34. $userProfile->region = $data->get('region');
  35. $userProfile->city = $data->get('city');
  36. $userProfile->zip = $data->get('zip');
  37. return $userProfile;
  38. }
  39. }