title: Login with Facebook in Symfony
body: <p>I am trying to login with Facebook with <strong><em>Symfony 3.4</em></strong>. I am following this <a href="https://hugo-soltys.com/blog/use-facebook-or-google-to-login-to-your-symfony-website-with-hwioauthbundle" rel="nofollow noreferrer">tutorial</a> but unfortunately facing this error</p>
  
  <blockquote>
    <p>Unrecognized field: facebookId</p>
  </blockquote>
  
  <p>I have tried this <a href="https://stackoverflow.com/questions/47524045/unrecognized-field-facebookid">Answer</a> but this couldn't fixed it for me.</p>
  
  <p>Here is my code</p>
  
  <p><strong><em>config.yml</em></strong></p>
  
  <pre><code>hwi_oauth:
  firewall_names: [secured_area]
  fosub:
      properties:
          facebook: facebookId
  resource_owners:
      facebook:
          type:                facebook
          client_id:           471421726653730
          client_secret:       4c0d30bfa73e2ec0ec3e94a0f9cab0e1
          options:
              display: popup
              auth_type: rerequest
              csrf: true
  </code></pre>
  
  <p><strong><em>security.yml</em></strong></p>
  
  <pre><code>        secured_area:
          pattern:    ^/
          anonymous: ~
          remember_me:
              secret:   '%secret%'
              lifetime: 604800 # 1 week in seconds
              path:     /
              #always_remember_me : true
          form_login:
              provider:   cms_dashboard_user
              login_path: cms_myuser_login
              check_path: cms_myuser_login_check
          logout:
              path:   cms_myuser_logout
              target: cms_myuser_login
              invalidate_session: false
          oauth:
              resource_owners:
                  facebook:           "/secured/login_facebook"
              login_path:        fos_user_security_login
              failure_path:      fos_user_security_login
              oauth_user_provider:
                  service: my.oauth_aware.user_provider.service
  </code></pre>
  
  <p><strong><em>services.yml</em></strong></p>
  
  <pre><code>    my.oauth_aware.user_provider.service:
      class: CMS\FrontUserBundle\Provider\MyFOSUBProvider
      arguments:
          - '@fos_user.user_manager'
          - { facebook: facebookId }
          - '@doctrine'
  </code></pre>
  
  <p><strong><em>routing.yml</em></strong></p>
  
  <pre><code>facebook_login:
      path: /secured/login_facebook
  hwi_oauth_redirect:
      resource: "@HWIOAuthBundle/Resources/config/routing/redirect.xml"
      prefix:   /connect
  
  hwi_oauth_connect:
      resource: "@HWIOAuthBundle/Resources/config/routing/connect.xml"
      prefix:   /connect
  
  hwi_oauth_login:
      resource: "@HWIOAuthBundle/Resources/config/routing/login.xml"
      prefix:   /login
  </code></pre>
  
  <p><strong><em>Front User Entity</em></strong></p>
  
  <pre><code>    /**
       * @ORM\Column(type="string", name="facebook_id", nullable=true)
       */
      protected $facebookId;
  
      /**
       * Set facebookId.
       *
       * @param string|null $facebookId
       *
       * @return FrontUser
       */
      public function setFacebookId($facebookId = null)
      {
         $this-&gt;facebookId = $facebookId;
  
         return $this;
      }
  
     /**
      * Get facebookId.
      *
      * @return string|null
      */
      public function getFacebookId()
      {
          return $this-&gt;facebookId;
      }
  </code></pre>
  
  <p><strong><em>Provider Class</em></strong></p>
  
  <pre><code>    &lt;?php
  
  namespace CMS\FrontUserBundle\Provider;
  
  use Doctrine\Bundle\DoctrineBundle\Registry;
  use FOS\UserBundle\Model\UserManagerInterface;
  use HWI\Bundle\OAuthBundle\OAuth\Response\UserResponseInterface;
  use HWI\Bundle\OAuthBundle\Security\Core\User\FOSUBUserProvider;
  use CMS\FrontUserBundle\Entity\FrontUser;
  
  class MyFOSUBProvider extends FOSUBUserProvider
  {
      private $doctrine;
  
      /**
       * @param UserManagerInterface $userManager
       * @param array $properties
       * @param Registry $doctrine
       */
      public function __construct(UserManagerInterface $userManager, array $properties, $doctrine)
      {
          parent::__construct($userManager, $properties);
  
          $this-&gt;doctrine = $doctrine;
      }
  
      /**
       * {@inheritdoc}
       */
      public function loadUserByOAuthUserResponse(UserResponseInterface $response)
      {
          $username = $response-&gt;getUsername();
          $property = $this-&gt;getProperty($response);
  
          $user = $this-&gt;userManager-&gt;findUserBy(array($this-&gt;getProperty($response) =&gt; $username));
  
          $email = $response-&gt;getEmail();
          // check if we already have this user
          $existing = $this-&gt;userManager-&gt;findUserBy(array('email' =&gt; $email));
          if ($existing instanceof FrontUser) {
              // in case of Facebook login, update the facebook_id
              if ($property == "facebookId") {
                  $existing-&gt;setFacebookId($username);
              }
              $this-&gt;userManager-&gt;updateUser($existing);
  
              return $existing;
          }
  
          // if we don't know the user, create it
          if (null === $user || null === $username) {
              /** @var User $user */
              $user = $this-&gt;userManager-&gt;createUser();
              $nick = "johndoe"; // to be changed
  
              $user-&gt;setLastLogin(new \DateTime());
              $user-&gt;setEnabled(true);
  
              $user-&gt;setUsername($nick);
              $user-&gt;setUsernameCanonical($nick);
              $user-&gt;setPassword(sha1(uniqid()));
              $user-&gt;addRole('ROLE_USER');
  
              if ($property == "facebookId") {
                  $user-&gt;setFacebookId($username);
              }
              if ($property == "googleId") {
                  $user-&gt;setGoogleId($username);
              }
          }
  
          $user-&gt;setEmail($response-&gt;getEmail());
          $user-&gt;setFirstname($response-&gt;getFirstName());
          $user-&gt;setLastname($response-&gt;getLastName());
  
          $this-&gt;userManager-&gt;updateUser($user);
  
          return $user;
      }
  }
  </code></pre>
  
  <p><strong><em>fos_user configuration</em></strong></p>
  
  <pre><code>fos_user:
  db_driver:      orm # can be orm or odm
  firewall_name:  main
  user_class:     Application\Sonata\UserBundle\Entity\User
  
  
  group:
      group_class:   Application\Sonata\UserBundle\Entity\Group
      group_manager: sonata.user.orm.group_manager # If you're using doctrine orm (use sonata.user.mongodb.group_manager for mongodb)
  
  service:
      user_manager: sonata.user.orm.user_manager
  
  from_email:
      address: "noreply@theemirates.com"
      sender_name: "The Emirates Brand"
  </code></pre>