/** * @param \Symfony\Component\Security\Core\Authentication\Token\TokenInterface $token * @return bool * @throws \Laelaps\Bundle\FacebookAuthentication\Exception\InvalidUser */ public function authenticate(TokenInterface $token) { $user = $this->getUserProvider()->loadUserByUsername($token->getUsername()); if (!$user instanceof UserInterface) { throw new InvalidUserException($user); } $authenticatedToken = new FacebookUserToken($user); $authenticatedToken->setAuthenticated(true); return $authenticatedToken; }
public function testThatFacebookUserTokenIsCreatedWithUserAndRolesAndTokenRolesPrevail() { $username = uniqid(); $userRoles = [uniqid(), uniqid()]; $tokenRoles = [uniqid(), uniqid()]; $user = $this->getMock('Symfony\\Component\\Security\\Core\\User\\UserInterface'); $user->expects($this->any())->method('getUsername')->will($this->returnValue($username)); $user->expects($this->any())->method('getRoles')->will($this->returnValue($userRoles)); $token = new FacebookUserToken($user, $tokenRoles); $this->assertSame($user, $token->getUser()); $this->assertSame($username, $token->getUsername()); $this->assertSame($tokenRoles, array_map(function (Role $role) { return $role->getRole(); }, $token->getRoles())); }