Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function getUserProfile()
 {
     $response = $this->apiRequest('me.json');
     $data = new Data\Collection($response);
     if (!$data->exists('id')) {
         throw new UnexpectedValueException('Provider API returned an unexpected response.');
     }
     $userProfile = new User\Profile();
     $userProfile->identifier = $data->get('id');
     $userProfile->displayName = $data->get('name');
     $userProfile->profileURL = 'https://www.reddit.com/user/' . $data->get('name') . '/';
     return $userProfile;
 }
Ejemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function getUserProfile()
 {
     $response = $this->apiRequest('users/me');
     $data = new Data\Collection($response);
     if (!$data->exists('user')) {
         throw new UnexpectedValueException('Provider API returned an unexpected response.');
     }
     $userProfile = new User\Profile();
     $data = $data->get('user');
     $userProfile->identifier = str_ireplace($this->apiBaseUrl . 'users/', '', $data->get('url'));
     $userProfile->description = $data->get('role');
     $userProfile->email = $data->get('email');
     $userProfile->firstName = $data->get('first_name');
     $userProfile->lastName = $data->get('last_name');
     $userProfile->displayName = trim(${$data}->get('first_name') . ' ' . $data->get('last_name'));
     return $userProfile;
 }
Ejemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function getUserProfile()
 {
     $response = $this->apiRequest('users/self/');
     $data = new Data\Collection($response);
     if (!$data->exists('id')) {
         throw new UnexpectedValueException('Provider API returned an unexpected response.');
     }
     $userProfile = new User\Profile();
     $data = $data->filter('id');
     $userProfile->identifier = $data->get('id');
     $userProfile->description = $data->get('bio');
     $userProfile->photoURL = $data->get('profile_picture');
     $userProfile->webSiteURL = $data->get('website');
     $userProfile->displayName = $data->get('full_name');
     $userProfile->displayName = $userProfile->displayName ?: $data->get('username');
     return $userProfile;
 }
Ejemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 protected function getUserContacts()
 {
     $contacts = [];
     $response = $this->apiRequest('me/contacts');
     if ($data->get('errcode')) {
         throw new UnexpectedValueException('Provider API returned an unexpected response.');
     }
     $data = new Data\Collection($response);
     foreach ($data->filter('data')->all() as $idx => $entry) {
         $userContact = new User\Contact();
         $userContact->identifier = $entry->get('id');
         $userContact->displayName = $entry->get('name');
         $userContact->email = $entry->filter('emails')->get('preferred');
         $contacts[] = $userContact;
     }
     return $contacts;
 }
Ejemplo n.º 5
0
 /**
  * {@inheritdoc}
  */
 public function getUserProfile()
 {
     $response = $this->apiRequest('user');
     $data = new Data\Collection($response);
     if (!$data->exists('id')) {
         throw new UnexpectedValueException('Provider API returned an unexpected response.');
     }
     $userProfile = new User\Profile();
     $userProfile->identifier = $data->get('id');
     $userProfile->profileURL = $data->get('html_url');
     $userProfile->photoURL = $data->get('avatar_url');
     $userProfile->description = $data->get('bio');
     $userProfile->region = $data->get('location');
     $userProfile->displayName = $data->get('name');
     $userProfile->displayName = $userProfile->displayName ?: $data->get('username');
     $userProfile->webSiteURL = $data->filter('links')->get('web');
     return $userProfile;
 }
Ejemplo n.º 6
0
 /**
  * {@inheritdoc}
  */
 public function getUserProfile()
 {
     $response = $this->apiRequest('users');
     $data = new Data\Collection($response);
     if (!$data->exists('id')) {
         throw new UnexpectedValueException('Provider API returned an unexpected response.');
     }
     $userProfile = new User\Profile();
     $data = $data->filter('user');
     $userProfile->identifier = $data->get('id');
     $userProfile->displayName = $data->get('username');
     $userProfile->description = $data->get('about');
     $userProfile->firstName = $data->get('firstname');
     $userProfile->lastName = $data->get('lastname');
     $userProfile->photoURL = $data->get('userpic_url');
     $userProfile->city = $data->get('city');
     $userProfile->region = $data->get('state');
     $userProfile->country = $data->get('country');
     $userProfile->profileURL = $data->exists('domain') ? 'http://' . $data->get('domain') : '';
     return $userProfile;
 }
Ejemplo n.º 7
0
 /**
  * {@inheritdoc}
  */
 public function getUserProfile()
 {
     $fields = ['id', 'email-address', 'first-name', 'last-name', 'headline', 'location', 'industry', 'picture-url', 'public-profile-url'];
     $response = $this->apiRequest('people/~:(' . implode(',', $this->fields) . ')?format=json');
     $data = new Data\Collection($response);
     if (!$data->exists('ID')) {
         throw new UnexpectedValueException('Provider API returned an unexpected response.');
     }
     $userProfile = new User\Profile();
     $userProfile->identifier = $data->get('ID');
     $userProfile->firstName = $data->get('firstName');
     $userProfile->lastName = $data->get('lastName');
     $userProfile->photoURL = $data->get('pictureUrl');
     $userProfile->profileURL = $data->get('publicProfileUrl');
     $userProfile->email = $data->get('headline');
     $userProfile->bio = $data->get('language');
     $userProfile->displayName = trim($userProfile->firstName . ' ' . $userProfile->lastName);
     return $userProfile;
 }
Ejemplo n.º 8
0
 /**
  * {@inheritdoc}
  */
 public function getUserProfile()
 {
     $response = $this->apiRequest('user/info');
     $data = new Data\Collection($response);
     if (!$data->exists('response')) {
         throw new UnexpectedValueException('Provider API returned an unexpected response.');
     }
     $userProfile = new User\Profile();
     $userProfile->displayName = $data->filter('response')->filter('user')->get('name');
     foreach ($data->filter('response')->filter('user')->filter('blogs')->all() as $blog) {
         if ($blog->get('primary') && $blog->exists('url')) {
             $userProfile->identifier = $blog->get('url');
             $userProfile->profileURL = $blog->get('url');
             $userProfile->webSiteURL = $blog->get('url');
             $userProfile->description = strip_tags($blog->get('description'));
             $bloghostname = explode('://', $blog->get('url'));
             $bloghostname = substr($bloghostname[1], 0, -1);
             $this->token('primary_blog', $bloghostname);
             break;
         }
     }
     return $userProfile;
 }
Ejemplo n.º 9
0
 /**
  * {@inheritdoc}
  */
 public function getUserProfile()
 {
     $response = $this->apiRequest('users/self');
     $data = new Data\Collection($response);
     if (!$data->exists('response')) {
         throw new UnexpectedValueException('Provider API returned an unexpected response.');
     }
     $userProfile = new User\Profile();
     $data = $data->filter('response')->filter('user');
     $userProfile->identifier = $data->get('id');
     $userProfile->firstName = $data->get('firstName');
     $userProfile->lastName = $data->get('lastName');
     $userProfile->gender = $data->get('gender');
     $userProfile->city = $data->get('homeCity');
     $userProfile->email = $data->filter('contact')->get('email');
     $userProfile->emailVerified = $userProfile->email;
     $userProfile->profileURL = 'https://www.foursquare.com/user/' . $userProfile->identifier;
     $userProfile->displayName = trim($userProfile->firstName . ' ' . $userProfile->lastName);
     if ($data->exists('photo')) {
         $userProfile->photoURL = $data->filter('photo')->get('prefix') . '150x150' . $data->filter('photo')->get('suffix');
     }
     return $userProfile;
 }
Ejemplo n.º 10
0
 /**
  * Returns the Current URL.
  *
  * @param bool $requestUri TRUE to use $_SERVER['REQUEST_URI'], FALSE for $_SERVER['PHP_SELF']
  *
  * @return string
  */
 public static function getCurrentUrl($requestUri = false)
 {
     $collection = new Data\Collection($_SERVER);
     $protocol = 'http://';
     if ($collection->get('HTTPS') && $collection->get('HTTPS') !== 'off' || $collection->get('HTTP_X_FORWARDED_PROTO') === 'https') {
         $protocol = 'https://';
     }
     return $protocol . $collection->get('HTTP_HOST') . $collection->get($requestUri ? 'REQUEST_URI' : 'PHP_SELF');
 }
Ejemplo n.º 11
0
 /**
  * {@inheritdoc}
  */
 public function getUserProfile()
 {
     $fields = array('uid', 'locale', 'first_name', 'last_name', 'name', 'gender', 'age', 'birthday', 'has_email', 'current_status', 'current_status_id', 'current_status_date', 'online', 'photo_id', 'pic_1', 'pic_2', 'pic1024x768', 'location', 'email');
     $sig = md5('application_key=' . $this->config->get('keys')['key'] . 'fields=' . implode(',', $fields) . 'method=users.getCurrentUser' . md5($this->token('access_token') . $this->config->get('keys')['secret']));
     $parameters = ['application_key' => $this->config->get('keys')['key'], 'method' => 'users.getCurrentUser', 'fields' => implode(',', $fields), 'sig' => $sig];
     $response = $this->apiRequest('', 'GET', $parameters);
     $data = new Data\Collection($response);
     if (!$data->exists('uid')) {
         throw new UnexpectedValueException('Provider API returned an unexpected response.');
     }
     $userProfile = new User\Profile();
     $userProfile->identifier = $data->get('uid');
     $userProfile->email = $data->get('email');
     $userProfile->firstName = $data->get('first_name');
     $userProfile->lastName = $data->get('last_name');
     $userProfile->displayName = $data->get('name');
     $userProfile->photoURL = $data->get('pic1024x768');
     $userProfile->profileURL = 'http://ok.ru/profile/' . $data->get('uid');
     return $userProfile;
 }
Ejemplo n.º 12
0
 /**
  * {@inheritdoc}
  */
 public function getUserProfile()
 {
     $response = $this->apiRequest('userdata');
     $data = new Data\Collection($response);
     if (!$data->exists('id')) {
         throw new UnexpectedValueException('Provider API returned an unexpected response.');
     }
     $userProfile = new User\Profile();
     $userProfile->identifier = $data->get('id');
     $userProfile->firstName = $data->get('firstName');
     $userProfile->displayName = $data->get('firstName');
     $userProfile->email = $data->get('email');
     $userProfile->emailVerified = $data->get('email');
     return $userProfile;
 }
Ejemplo n.º 13
0
 /**
  * {@inheritdoc}
  */
 public function getUserProfile()
 {
     $response = $this->apiRequest('users.getInfo');
     $data = new Data\Collection($response[0]);
     if (!$data->exists('uid')) {
         throw new UnexpectedValueException('Provider API returned an unexpected response.');
     }
     $userProfile = new User\Profile();
     $userProfile->identifier = $data->get('uid');
     $userProfile->firstName = $data->get('first_name');
     $userProfile->lastName = $data->get('last_name');
     $userProfile->displayName = $data->get('nick');
     $userProfile->photoURL = $data->get('pic');
     $userProfile->profileURL = $data->get('link');
     $userProfile->gender = $data->get('sex');
     $userProfile->email = $data->get('email');
     $userProfile->emailVerified = $data->get('email');
     return $userProfile;
 }
Ejemplo n.º 14
0
 /**
  * {@inheritdoc}
  */
 public function getUserProfile()
 {
     $response = $this->apiRequest('user');
     $data = new Data\Collection($response);
     if (!$data->exists('id')) {
         throw new UnexpectedValueException('Provider API returned an unexpected response.');
     }
     $userProfile = new User\Profile();
     $userProfile->identifier = $data->get('id');
     $userProfile->displayName = $data->get('name');
     $userProfile->description = $data->get('bio');
     $userProfile->photoURL = $data->get('avatar_url');
     $userProfile->profileURL = $data->get('html_url');
     $userProfile->email = $data->get('email');
     $userProfile->webSiteURL = $data->get('blog');
     $userProfile->region = $data->get('location');
     $userProfile->displayName = $userProfile->displayName ?: $data->get('login');
     if (empty($userProfile->email) && strpos($this->scope, 'user:email') !== false) {
         $userProfile = $this->requestUserEmail($userProfile);
     }
     return $userProfile;
 }
Ejemplo n.º 15
0
 /**
  * {@inheritdoc}
  */
 public function getUserActivity($stream)
 {
     $activities = [];
     $apiUrl = $stream == 'me' ? '/me/feed' : '/me/home';
     $response = $this->apiRequest($apiUrl);
     $data = new Data\Collection($response);
     if (!$data->exists('data')) {
         throw new UnexpectedValueException('Provider API returned an unexpected response.');
     }
     if ($data->filter('data')->isEmpty()) {
         return $activities;
     }
     foreach ($data->filter('data')->all() as $item) {
         $activities[] = $this->fetchUserActivity($item);
     }
     return $activities;
 }
Ejemplo n.º 16
0
 /**
  * Retrieve Google plus contacts
  *
  *  ..
  */
 protected function getGplusContacts($extraParams)
 {
     $contacts = [];
     $url = 'https://www.googleapis.com/plus/v1/people/me/people/visible?' . http_build_query($extraParams);
     $response = $this->apiRequest($url);
     $data = new Data\Collection($response);
     foreach ($data->filter('items')->all() as $idx => $item) {
         $userContact = new User\Contact();
         $userContact->identifier = $item->get('id');
         $userContact->email = $item->get('email');
         $userContact->displayName = $item->get('displayName');
         $userContact->description = $item->get('objectType');
         $userContact->photoURL = $item->filter('image')->get('url');
         $userContact->profileURL = $item->get('url');
         $contacts[] = $userContact;
     }
     return $contacts;
 }
Ejemplo n.º 17
0
 /**
  * Validate Access Token Response
  *
  * OAuth Core: If successful, the Service Provider generates an Access Token and Token Secret and returns
  * them in the HTTP response body.
  *
  * The Access Token and Token Secret are stored by the Consumer and used when signing Protected Resources requests.
  *
  * http://oauth.net/core/1.0a/#auth_step3
  * 6.3.2. Service Provider Grants an Access Token
  *
  * @param string $response
  *
  * @return \Hybridauth\Data\Collection
  * @throws InvalidAccessTokenException
  */
 protected function validateAccessTokenExchange($response)
 {
     /**
      * The response contains the following parameters:
      *
      *    - oauth_token         The Access Token.
      *    - oauth_token_secret  The Token Secret.
      *
      * http://oauth.net/core/1.0/#auth_step3
      * 6.3.2. Service Provider Grants an Access Token
      *
      * Example of a successful response:
      *
      *  HTTP/1.1 200 OK
      *  Content-Type: text/html; charset=utf-8
      *  Cache-Control: no-store
      *  Pragma: no-cache
      *
      *  oauth_token=sHeLU7Far428zj8PzlWR75&oauth_token_secret=fXb30rzoG&oauth_callback_confirmed=true
      *
      * OAuthUtil::parse_parameters will attempt to decode the raw response into an array.
      */
     $tokens = OAuthUtil::parse_parameters($response);
     $collection = new Data\Collection($tokens);
     if (!$collection->exists('oauth_token')) {
         throw new InvalidAccessTokenException('Provider returned an invalid access_token: ' . htmlentities($response));
     }
     $this->consumerToken = new OAuthConsumer($collection->get('oauth_token'), $collection->get('oauth_token_secret'));
     $this->token('access_token', $collection->get('oauth_token'));
     $this->token('access_token_secret', $collection->get('oauth_token_secret'));
     $this->deleteToken('request_token');
     $this->deleteToken('request_token_secret');
     return $collection;
 }
Ejemplo n.º 18
0
 /**
  * {@inheritdoc}
  */
 public function getUserActivity($stream)
 {
     $activities = [];
     $apiUrl = $stream == 'me' ? 'statuses/user_timeline.json' : 'statuses/home_timeline.json';
     $response = $this->apiRequest($apiUrl);
     $data = new Data\Collection($response);
     if ($data->isEmpty()) {
         return $activities;
     }
     foreach ($data->all() as $item) {
         $activities[] = $this->fetchUserActivity($item);
     }
     return $activities;
 }
Ejemplo n.º 19
0
 /**
  * {@inheritdoc}
  */
 public function getUserProfile()
 {
     $response = $this->apiRequest('me/');
     $data = new Data\Collection($response);
     if (!$data->exists('ID')) {
         throw new UnexpectedValueException('Provider API returned an unexpected response.');
     }
     $userProfile = new User\Profile();
     $userProfile->identifier = $data->get('ID');
     $userProfile->displayName = $data->get('display_name');
     $userProfile->photoURL = $data->get('avatar_URL');
     $userProfile->profileURL = $data->get('profile_URL');
     $userProfile->email = $data->get('email');
     $userProfile->language = $data->get('language');
     $userProfile->displayName = $userProfile->displayName ?: $data->get('username');
     $userProfile->emailVerified = 1 == $data->get('email_verified') ? $data->get('email') : '';
     return $userProfile;
 }
Ejemplo n.º 20
0
 /**
  * Fetch user profile from received openid attributes
  */
 protected function fetchUserProfile($openidAttributes)
 {
     $data = new Data\Collection($openidAttributes);
     $userProfile = new User\Profile();
     $userProfile->identifier = $this->openIdClient->identity;
     $userProfile->firstName = $data->get('namePerson/first');
     $userProfile->lastName = $data->get('namePerson/last');
     $userProfile->email = $data->get('contact/email');
     $userProfile->language = $data->get('pref/language');
     $userProfile->country = $data->get('contact/country/home');
     $userProfile->zip = $data->get('contact/postalCode/home');
     $userProfile->gender = $data->get('person/gender');
     $userProfile->photoURL = $data->get('media/image/default');
     $userProfile->birthDay = $data->get('birthDate/birthDay');
     $userProfile->birthMonth = $data->get('birthDate/birthMonth');
     $userProfile->birthYear = $data->get('birthDate/birthDate');
     $userProfile = $this->fetchUserGender($userProfile, $data->get('person/gender'));
     $userProfile = $this->fetchUserDisplayName($userProfile, $data);
     return $userProfile;
 }
Ejemplo n.º 21
0
 /**
  * {@inheritdoc}
  */
 public function getUserProfile()
 {
     $parameters = ['uid' => $this->token('user_id'), 'fields' => 'first_name,last_name,nickname,screen_name,sex,' . 'bdate,timezone,photo_rec,photo_big,photo_max_orig'];
     $response = $this->apiRequest('users.get', 'GET', $parameters);
     $data = new Data\Collection($response->response[0]);
     if (!$data->exists('uid')) {
         throw new UnexpectedValueException('Provider API returned an unexpected response.');
     }
     $userProfile = new User\Profile();
     $userProfile->identifier = $data->get('uid');
     $userProfile->email = $this->token('email');
     $userProfile->firstName = $data->get('first_name');
     $userProfile->lastName = $data->get('last_name');
     $userProfile->displayName = $data->get('screen_name');
     $userProfile->photoURL = $data->get('photo_max_orig');
     $userProfile->profileURL = $data->get('screen_name') ? 'http://vk.com/' . $data->get('screen_name') : '';
     if ($data->exists('sex')) {
         switch ($data->get('sex')) {
             case 1:
                 $userProfile->gender = 'female';
                 break;
             case 2:
                 $userProfile->gender = 'male';
                 break;
         }
     }
     return $userProfile;
 }
Ejemplo n.º 22
0
 /**
  * Validate Access Token Response
  *
  * RFC6749: If the access token request is valid and authorized, the
  * authorization server issues an access token and optional refresh token.
  * If the request client authentication failed or is invalid, the authorization
  * server returns an error response as described in Section 5.2.
  *
  * Example of a successful response:
  *
  *  HTTP/1.1 200 OK
  *  Content-Type: application/json;charset=UTF-8
  *  Cache-Control: no-store
  *  Pragma: no-cache
  *
  *  {
  *      "access_token":"2YotnFZFEjr1zCsicMWpAA",
  *      "token_type":"example",
  *      "expires_in":3600,
  *      "refresh_token":"tGzv3JOkF0XG5Qx2TlKWIA",
  *      "example_parameter":"example_value"
  *  }
  *
  * http://tools.ietf.org/html/rfc6749#section-4.1.4
  *
  * This method uses Data_Parser to attempt to decodes the raw $response (usually JSON)
  * into a data collection.
  *
  * @param string $response
  *
  * @return \Hybridauth\Data\Collection
  * @throws InvalidAccessTokenException
  */
 protected function validateAccessTokenExchange($response)
 {
     $data = (new Data\Parser())->parse($response);
     $collection = new Data\Collection($data);
     if (!$collection->exists('access_token')) {
         throw new InvalidAccessTokenException('Provider returned an invalid access_token: ' . htmlentities($response));
     }
     $this->token('access_token', $collection->get('access_token'));
     $this->token('token_type', $collection->get('token_type'));
     $this->token('refresh_token', $collection->get('refresh_token'));
     $this->token('expires_in', $collection->get('expires_in'));
     // calculate when the access token expire
     if ($collection->exists('expires_in')) {
         $expires_at = time() + (int) $collection->get('expires_in');
         $this->token('access_token_expires_at', $expires_at);
     }
     $this->deleteToken('authorization_state');
     return $collection;
 }