How to integrate Sonata User Bundle with HWIOAuthBundle. At HWIOAuthBundle the doc is FOSUserBundle. But there is no doc for SonataUserBundle in NET. I googled net and found nothing.
As per HWIOAuthBundle doc I created ,
Application\Sonata\UserBundle\Entity\User
/**
* @ORM\Column(name="facebook_id", type="string", length=255, nullable=true)
*/
private $facebookId;
private $facebookAccessToken;
/**
* @param string $facebookId
* @return User
*/
public function setFacebookId($facebookId)
{
$this->facebookId = $facebookId;
return $this;
}
/**
* @return string
*/
public function getFacebookId()
{
return $this->facebookId;
}
/**
* @param string $facebookAccessToken
* @return User
*/
public function setFacebookAccessToken($facebookAccessToken)
{
$this->facebookAccessToken = $facebookAccessToken;
return $this;
}
/**
* @return string
*/
public function getFacebookAccessToken()
{
return $this->facebookAccessToken;
}
My Provider class (from net)
public function connect(UserInterface $user, UserResponseInterface $response) {
$property = $this->getProperty($response);
$username = $response->getUsername();
$service = $response->getResourceOwner()->getName();
$setter = 'set' . ucfirst($service);
$setter_id = $setter . 'Id';
$setter_token = $setter . 'AccessToken';
if (null !== $previousUser = $this->userManager->findUserBy([$property => $username])) {
$previousUser->$setter_id(null);
$previousUser->$setter_token(null);
$this->userManager->updateUser($previousUser);
}
$user->$setter_id($username);
$user->$setter_token($response->getAccessToken());
$this->userManager->updateUser($user);
}
public function loadUserByOAuthUserResponse(UserResponseInterface $response) {
$username = $response->getUsername();
$user = $this->userManager->findUserBy([$this->getProperty($response) => $username]);
if (null === $user) {
$service = $response->getResourceOwner()->getName();
$setter = 'set' . ucfirst($service);
$setter_id = $setter . 'Id';
$setter_token = $setter . 'AccessToken';
$user = $this->userManager->createUser();
$user->$setter_id($username);
$user->$setter_token($response->getAccessToken());
$user->setUsername($username);
$user->setEmail($response->getEmail());
$user->setPlainPassword($response->getAccessToken());
$user->setEnabled(TRUE);
$this->userManager->updateUser($user);
return $user;
}
$user = parent::loadUserByOAuthUserResponse($response);
$serviceName = $response->getResourceOwner()->getName();
$setter = 'set' . ucfirst($serviceName) . 'AccessToken';
$user->$setter($response->getAccessToken());
return $user;
}
But I get error
Unrecognized field: facebookID
I also changed $setter_id = $setter . 'Id';
to $setter_id = $setter . 'Uid';
But still error.
as per sonata user entity
UPDATE 01:
At Application\Sonata\UserBundle\Entity\User
I changed $facebookID
(and all its related...). Then I get error invalid password.