Esempio n. 1
0
 /**
  * Returns user profile
  *
  * Examples:
  *
  *	$data = $hybridauth->authenticate( "Google" )->getUserProfile();
  */
 function getUserProfile()
 {
     $response = $this->signedRequest("https://www.googleapis.com/oauth2/v1/userinfo");
     $response = json_decode($response);
     // Provider Errors shall not pass silently
     if (!$response || !isset($response->id)) {
         throw new Exception('User profile request failed: Provider returned an invalid response. ' . 'HTTP client state: (' . $this->httpClient->getState() . ')', Exception::AUTHENTIFICATION_FAILED, $this);
     }
     $parser = function ($property) use($response) {
         return property_exists($response, $property) ? $response->{$property} : null;
     };
     $profile = new Profile();
     $profile->setIdentifier($parser('id'));
     $profile->setFirstName($parser('given_name'));
     $profile->setLastName($parser('family_name'));
     $profile->setDisplayName($parser('name'));
     $profile->setPhotoURL($parser('picture'));
     $profile->setProfileURL($parser('link'));
     $profile->setGender($parser('gender'));
     $profile->setEmail($parser('email'));
     $profile->setLanguage($parser('locale'));
     if ($parser('birthday')) {
         list($y, $m, $d) = explode('-', $response->birthday);
         $profile->setBirthDay($d);
         $profile->setBirthMonth($m);
         $profile->setBirthYear($y);
     }
     if ($parser('verified_email')) {
         $profile->setEmailVerified($profile->getEmail());
     }
     return $profile;
 }
Esempio n. 2
0
 /**
  * Returns user profile
  *
  * Examples:
  *
  *	$data = $hybridauth->authenticate( "Facebook" )->getUserProfile();
  */
 function getUserProfile()
 {
     // request user infos
     $response = $this->signedRequest("me");
     $response = json_decode($response);
     if (!isset($response->id) || isset($response->error)) {
         throw new Exception('User profile request failed: Provider returned an invalid response. ' . 'HTTP client state: (' . $this->httpClient->getState() . ')', Exception::USER_PROFILE_REQUEST_FAILED, $this);
     }
     $parser = function ($property) use($response) {
         return property_exists($response, $property) ? $response->{$property} : null;
     };
     $profile = new Profile();
     $profile->setIdentifier($parser('id'));
     $profile->setFirstName($parser('first_name'));
     $profile->setLastName($parser('last_name'));
     $profile->setDisplayName($parser('name'));
     $profile->setProfileURL($parser('link'));
     $profile->setWebSiteURL($parser('website'));
     $profile->setGender($parser('gender'));
     $profile->setDescription($parser('bio'));
     $profile->setEmail($parser('email'));
     $profile->setLanguage($parser('locale'));
     $profile->setPhotoURL('https://graph.facebook.com/' . $profile->getIdentifier() . '/picture?width=150&height=150');
     if ($parser('birthday')) {
         list($m, $d, $y) = explode("/", $parser('birthday'));
         $profile->setBirthDay($d);
         $profile->setBirthMonth($m);
         $profile->setBirthYear($y);
     }
     if ($parser('verified')) {
         $profile->setEmailVerified($profile->getEmail());
     }
     return $profile;
 }
 /**
  * Get the eMail-Address of the user
  *
  * @return string
  */
 public function getMail()
 {
     return $this->user->getEmail();
 }