/**
  * @see OAuth2\IOAuth2GrantExtension::checkGrantExtension
  */
 public function checkGrantExtension(IOAuth2Client $client, array $inputData, array $authHeaders)
 {
     if (!isset($inputData['facebook_access_token'])) {
         return false;
     }
     $this->facebookSdk->setDefaultAccessToken($inputData['facebook_access_token']);
     try {
         // Try to get the user with the facebook token from Open Graph
         $fbData = $this->facebookSdk->get('/me?fields=email,id,first_name,last_name,name,name_format');
         if (!$fbData instanceof \Facebook\FacebookResponse) {
             return false;
         }
         // Check if a user match in database with the facebook id
         $user = $this->userManager->findUserBy(['facebookId' => $fbData->getDecodedBody()['id']]);
         // If none found, try to match email
         if (null === $user && isset($fbData->getDecodedBody()['email'])) {
             $user = $this->userManager->findUserBy(['email' => $fbData->getDecodedBody()['email']]);
         }
         // If no user found, register a new user and grant token
         if (null === $user) {
             // TODO: Create new user
             return false;
         } else {
             // Else, return the access_token for the user
             // Associate user with facebookId
             $user->setFacebookId($fbData->getDecodedBody()['id']);
             $this->userManager->updateUser($user);
             return array('data' => $user);
         }
     } catch (\FacebookApiExceptionion $e) {
         return false;
     }
 }
예제 #2
0
 /**
  * 
  * @param unknown $username
  * @throws UsernameNotFoundException
  * @return unknown
  */
 public function loadUserByUsername($username)
 {
     $user = $this->findUserByFbId($username);
     try {
         $fbdata = $this->facebook->api('/me');
     } catch (FacebookApiException $e) {
         $fbdata = null;
     }
     if (empty($user) and !empty($fbdata)) {
         $user = $this->userManager->findUserBy(array('email' => $fbdata['email']));
     }
     if (!empty($fbdata)) {
         if (empty($user)) {
             $user = $this->userManager->createUser();
             $user->setEnabled(true);
             $user->setPassword('');
         }
         // TODO use http://developers.facebook.com/docs/api/realtime
         $user->setFBData($fbdata);
         if (count($this->validator->validate($user, 'Facebook'))) {
             // TODO: the user was found obviously, but doesnt match our expectations, do something smart
             throw new UsernameNotFoundException('The facebook user could not be stored');
         }
         $this->userManager->updateUser($user);
     }
     if (empty($user)) {
         throw new UsernameNotFoundException('The user is not authenticated on facebook');
     }
     return $user;
 }
예제 #3
0
 /**
  * {@inheritDoc}
  */
 public function loadUserByOAuthUserResponse(UserResponseInterface $response)
 {
     $user = $this->manager->findUserBy(array($response->getResourceOwner()->getName() . 'Id' => $response->getResponse()['id']));
     if (null === $user) {
         return $this->createUserByOAuthUserResponse($response);
     }
     return $user;
 }
 /**
  * Gets or creates user profile, given user's ID
  *
  * @param integer $id ID
  *
  * @return UserProfile $profile
  */
 public function findOrCreateByUserID($id)
 {
     $profile = $this->repo->findByUserId($id);
     if ($profile) {
         $profile = $this->attachMissingUserProfileValues($profile);
     } else {
         $user = $this->userManager->findUserBy(array('id' => $id));
         $profile = $this->createUserProfileIfMissing($user);
     }
     return $profile;
 }
 /**
  * @inheritdoc
  */
 public function getUserFromOAuthResponse($providerName, array $data)
 {
     $field = $providerName . 'Id';
     if ($user = $this->userManager->findUserBy([$field => $data['id']])) {
         if (isset($data['data']['email'])) {
             $user->setEmail($data['data']['email']);
         }
         return $user;
     }
     if (isset($data['data']['email'])) {
         $user->setEmail($data['data']['email']);
     }
     $user = $this->userManipulator->create($data['data']['name'], 'secret', '', true, false);
     $setter = "set" . ucfirst($providerName) . 'Id';
     $user->{$setter}($data['id']);
     $this->userManager->updateUser($user);
     return $user;
 }
 public function createOrReturnUser($email, $superAdmin = false, $password = '******', $firstName = 'TestUser', $lastName = 'UserProfile', $enabled = true)
 {
     $user = $this->userManager->findUserBy(array('email' => $email));
     if ($user == null) {
         // TODO: figure out how to customize this for each app's own UserManipulator
         $manipulatorMethod = $this->container->getParameter('crisistextline.user_profile.user_manipulator')['method'];
         $user = $this->userManipulator->{$manipulatorMethod}($email, $password, $firstName, $lastName, $enabled, $superAdmin);
     }
     return $user;
 }
예제 #7
0
 public function getUserByToken($token)
 {
     if (!$token instanceof HttpToken) {
         $token = $this->entityManager->getRepository('CoreSiteAPIAuthBundle:HttpToken')->getToken($token);
     }
     if (!$token instanceof HttpToken) {
         return false;
     }
     $user = $this->userManager->findUserBy(array('id' => $token->getUserId()));
     if (!$user instanceof UserInterface) {
         return false;
     }
     return $user;
 }
예제 #8
0
 public function findUserByTwitterUsername($twitterUsername)
 {
     return $this->userManager->findUserBy(array('twitter_username' => $twitterUsername));
 }
예제 #9
0
 public function findUserByUsernameOrEmail($username)
 {
     if (is_numeric($cpf = preg_replace('/[^0-9]/', '', $username)) && strlen($cpf) == 11) {
         $person = parent::findUserBy(array('cpf' => $cpf));
         if ($person !== null) {
             return $person;
         }
     }
     return parent::findUserByUsernameOrEmail($username);
 }
예제 #10
0
 public function testFindUserBy()
 {
     $crit = array("foo" => "bar");
     $this->repository->expects($this->once())->method('findOneBy')->with($this->equalTo($crit))->will($this->returnValue(array()));
     $this->userManager->findUserBy($crit);
 }
	public function findUserByFbId($fbId)
	{
		return $this->userManager->findUserBy(array('facebookId' => $fbId));
	}
예제 #12
0
 /**
  * {@inheritdoc}
  */
 public function findOneBy(array $criteria, array $orderBy = null)
 {
     return parent::findUserBy($criteria);
 }