Ejemplo n.º 1
0
 public function authenticate(TokenInterface $token)
 {
     if (!$this->supports($token)) {
         return null;
     }
     $user = $token->getUser();
     if ($user instanceof UserInterface) {
         $this->userChecker->checkPostAuth($user);
         $newToken = new FacebookUserToken($this->providerKey, $user, $user->getRoles());
         $newToken->setAttributes($token->getAttributes());
         return $newToken;
     }
     try {
         if ($uid = $this->facebook->getUser()) {
             $newToken = $this->createAuthenticatedToken($uid);
             $newToken->setAttributes($token->getAttributes());
             return $newToken;
         }
     } catch (AuthenticationException $failed) {
         throw $failed;
     } catch (\Exception $failed) {
         throw new AuthenticationException($failed->getMessage(), null, (int) $failed->getCode(), $failed);
     }
     throw new AuthenticationException('The Facebook user could not be retrieved from the session.');
 }
 public function authenticate(TokenInterface $token)
 {
     if (!$this->supports($token)) {
         return null;
     }
     $user = $token->getUser();
     if ($user instanceof UserInterface) {
         $this->userChecker->checkPostAuth($user);
         $newToken = new FacebookUserToken($this->providerKey, $user, $user->getRoles(), $token->getAccessToken());
         $newToken->setAttributes($token->getAttributes());
         return $newToken;
     }
     if (!is_null($token->getAccessToken())) {
         $this->facebook->setAccessToken($token->getAccessToken());
     }
     if ($uid = $this->facebook->getUser()) {
         $newToken = $this->createAuthenticatedToken($uid, $token->getAccessToken());
         $newToken->setAttributes($token->getAttributes());
         return $newToken;
     }
     throw new AuthenticationException('The Facebook user could not be retrieved from the session.');
 }
 /**
  * @dataProvider provider
  */
 public function testThatAlwaysReturnEmptyCredentials($uid, $roles)
 {
     $token = new FacebookUserToken($uid, $roles);
     $this->assertEquals('', $token->getCredentials());
 }