Exemple #1
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');
 }
Exemple #2
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;
 }
Exemple #3
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;
 }
Exemple #4
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;
 }
Exemple #5
0
 /**
  * {@inheritdoc}
  */
 public function getUserContacts()
 {
     $contacts = [];
     $parameters = ['cursor' => '-1'];
     $response = $this->apiRequest('friends/ids.json', 'GET', $parameters);
     $data = new Data\Collection($response);
     if (!$data->exists('ids')) {
         throw new UnexpectedValueException('Provider API returned an unexpected response.');
     }
     if ($data->filter('ids')->isEmpty()) {
         return $contacts;
     }
     // 75 id per time should be okey
     $contactsIds = array_chunk((array) $data->get('ids'), 75);
     foreach ($contactsIds as $chunk) {
         $parameters = ['user_id' => implode(',', $chunk)];
         try {
             $response = $this->apiRequest('users/lookup.json', 'GET', $parameters);
             $data = (new Parser($response))->toCollection();
         } catch (Exception $e) {
             continue;
         }
         foreach ($data->all() as $item) {
             $contacts[] = $this->fetchUserContacts($item);
         }
     }
     return $contacts;
 }
Exemple #6
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;
 }
Exemple #7
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;
 }
Exemple #8
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('name');
     $userProfile->firstName = $data->get('first_name');
     $userProfile->lastName = $data->get('last_name');
     $userProfile->gender = $data->get('gender');
     $userProfile->profileURL = $data->get('link');
     $userProfile->email = $data->filter('emails')->get('preferred');
     $userProfile->emailVerified = $data->filter('emails')->get('account');
     $userProfile->birthDay = $data->get('birth_day');
     $userProfile->birthMonth = $data->get('birth_month');
     $userProfile->birthYear = $data->get('birth_year');
     return $userProfile;
 }
Exemple #9
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;
 }
Exemple #10
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;
 }
Exemple #11
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;
 }
Exemple #12
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;
 }
Exemple #13
0
 /**
  * {@inheritdoc}
  */
 public function getUserProfile($callback = null)
 {
     $response = $this->apiRequest('me?fields=id,name,first_name,last_name,link,website,gender,locale,about,email,hometown,verified,birthday');
     $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->firstName = $data->get('first_name');
     $userProfile->lastName = $data->get('last_name');
     $userProfile->profileURL = $data->get('link');
     $userProfile->webSiteURL = $data->get('website');
     $userProfile->gender = $data->get('gender');
     $userProfile->language = $data->get('locale');
     $userProfile->description = $data->get('about');
     $userProfile->email = $data->get('email');
     $userProfile->region = $data->filter('hometown')->get('name');
     $userProfile->photoURL = $this->apiBaseUrl . $userProfile->identifier . '/picture?width=150&height=150';
     $userProfile->emailVerified = $data->get('verified') == 1 ? $userProfile->email : '';
     $userProfile = $this->fetchUserRegion($userProfile, $userProfile);
     $userProfile = $this->fetchBirthday($userProfile, $data->get('birthday'));
     return $userProfile;
 }
Exemple #14
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;
 }
Exemple #15
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;
 }
Exemple #16
0
 /**
  * {@inheritdoc}
  */
 public function getUserProfile()
 {
     $response = $this->apiRequest('people/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->firstName = $data->filter('name')->get('givenName');
     $userProfile->lastName = $data->filter('name')->get('familyName');
     $userProfile->displayName = $data->get('displayName');
     $userProfile->photoURL = $data->get('image');
     $userProfile->profileURL = $data->get('url');
     $userProfile->description = $data->get('aboutMe');
     $userProfile->gender = $data->get('gender');
     $userProfile->language = $data->get('language');
     $userProfile->email = $data->get('email');
     $userProfile->phone = $data->get('phone');
     $userProfile->country = $data->get('country');
     $userProfile->region = $data->get('region');
     $userProfile->zip = $data->get('zip');
     if ($data->filter('image')->exists('url')) {
         $userProfile->photoURL = substr($data->filter('image')->get('url'), 0, -2) . 150;
     }
     $userProfile = $this->fetchUserEmail($userProfile, $data);
     $userProfile = $this->fetchUserProfileUrl($userProfile, $data);
     $userProfile = $this->fetchBirthday($userProfile, $data->get('birthday'));
     $userProfile->emailVerified = $data->get('verified') ? $userProfile->email : '';
     return $userProfile;
 }
Exemple #17
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;
 }