/** * {@inheritDoc} */ public function connect(UserInterface $user, UserResponseInterface $response) { $class = get_class($user); if (!$this->supportsClass($class)) { throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', $class)); } $property = $this->getProperty($response); $username = $response->getUsername(); $service = $response->getResourceOwner()->getName(); if (null !== ($previousUser = $this->repository->findOneBy(array($property => $username)))) { $this->disconnect($previousUser, $response); } $idField = $service . 'Id'; $tokenField = $service . 'AccessToken'; $this->accessor->setValue($user, $idField, $username); $this->accessor->setValue($user, $tokenField, $response->getAccessToken()); $this->em->persist($user); $this->em->flush(); }