This class is returned when you request user details form an OAuth2 server. This class standardizes the data that you get back because every OAuth2 server has its own user structure.
Ejemplo n.º 1
0
 /**
  * This method is called automatically when the OAuth2 server returns a response containing user details.
  * The method should process the response an return and instance of OAuth2User.
  *
  * @param array $result OAuth2 server response.
  *
  * @return OAuth2User
  * @throws OAuth2Exception
  */
 protected function processUserDetails($result)
 {
     $result = self::arr($result['result']);
     if ($result->keyExists('error')) {
         throw new OAuth2Exception($result->key('error'));
     }
     $user = new OAuth2User($result->key('given_name'), $result->key('email', '', true));
     $user->setProfileId($result->key('id', '', true));
     $user->setFirstName($result->key('given_name', '', true));
     $user->setLastName($result->key('family_name', '', true));
     $user->setProfileUrl($result->key('link', '', true));
     $user->setAvatarUrl($result->key('picture', '', true));
     $user->setGender($result->key('gender', '', true));
     $user->setServiceName('google');
     return $user;
 }
Ejemplo n.º 2
0
 /**
  * @param OAuth2User $u
  *
  * @dataProvider dataProvider
  * @expectedException \Webiny\Component\OAuth2\OAuth2Exception
  */
 public function testSetGetGenderException($u)
 {
     $gender = 'exception';
     $u->setGender($gender);
     $this->assertSame($gender, $u->getGender());
     $this->assertSame($gender, $u->gender);
 }
Ejemplo n.º 3
0
 /**
  * This method is called automatically when the OAuth2 server returns a response containing user details.
  * The method should process the response an return and instance of OAuth2User.
  *
  * @param array $result OAuth2 server response.
  *
  * @return OAuth2User
  * @throws OAuth2Exception
  */
 protected function processUserDetails($result)
 {
     $result = self::arr($result['result']);
     if ($result->keyExists('status') && $result->key('status') != 200) {
         throw new OAuth2Exception($result->key('message'));
     }
     $user = new OAuth2User($result->key('firstName', '', true), $result->key('emailAddress', '', true));
     $user->setProfileId($result->key('id', '', true));
     $user->setFirstName($result->key('firstName', '', true));
     $user->setLastName($result->key('lastName', '', true));
     $user->setProfileUrl($result->key('publicProfileUrl', '', true));
     $user->setAvatarUrl($result->key('pictureUrl', '', true));
     $user->setServiceName('linkedin');
     return $user;
 }
Ejemplo n.º 4
0
 /**
  * This method is called automatically when the OAuth2 server returns a response containing user details.
  * The method should process the response an return and instance of OAuth2User.
  *
  * @param array $result OAuth2 server response.
  *
  * @return OAuth2User
  * @throws \Webiny\Component\OAuth2\OAuth2Exception
  */
 public function processUserDetails($result)
 {
     $result = $this->arr($result['result']);
     if ($result->keyExists('error')) {
         throw new OAuth2Exception($result->keyNested('error.message'));
     }
     $user = new OAuth2User($result->key('username', '', true), $result->key('email', '', true));
     $user->setProfileId($result->key('id', '', true));
     $user->setFirstName($result->key('first_name', '', true));
     $user->setLastName($result->key('last_name', '', true));
     $user->setProfileUrl($result->key('link', '', true));
     $user->setAvatarUrl('http://graph.facebook.com/' . $user->profileId . '/picture?width=160&height=160');
     $user->setLastUpdateTime(strtotime($result->key('updated_time', '', true)));
     $user->setGender($result->key('gender', '', true));
     $user->setServiceName('facebook');
     return $user;
 }