質問

In my app I need to be able to let users log in and connect their accounts via OAuth. I'm using HWIOAuthBundle and FOSUserBundle to accomplish that. But there's a problem: when I'm registering via Facebook or whatnot a User entity is automatically created and persisted to the database, and a token is created for the user.

What I actually need is to only fetch some data the provider gives me and map it to a user yet to be persisted.

役に立ちましたか?

解決

If I understand, you would like to add for example Facebook information to a logged-in user.

So what you have to do in your provider is to check that there is a connected user and then add information:

if (($this->container->get('security.context')->getToken() instanceof AbstractToken) {
    $loggedUser = $this->container->get('security.context')->getToken()->getUser();
    $loggedUser->setFacebookId($fbdata['id']);

    /* userManager is fos_user.user_manager service */
    $this->userManager->updateUser($loggedUser);

    return $loggedUser;
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top