12 comments

  1. Thankyou so much. After a week of try I found your solution as the best. I used in FOSUserBundle What i did is , Just changed “u.googleId” to “u.gplusUid” and I just changed the ”use Foggyline\Bundle\TickerBundle\Entity\User; ” to ”use Application\Sonata\UserBundle\Entity\User;”. It works. Hello friend, here google is hardcoded in $em, = I tried with google and facebook both works fine. But the problem is I can’t work both at same time. I need to fine the PROVIDER. Can you please “how to get provider code?”

  2. Hi, i have implemented this code and it works properly, so, thank you so much for this tutorial.

    Now, im trying to do it with facebook too, but i wonder how to identify who is the provider (facebook, google, etc) because all of them are pointing to the same provider class ( Foggyline\Bundle\TickerBundle\Auth\OAuthProvider).

    I guess that i need to identify who is the provider in the own class and depending on this i have to get the response. Am i wrong?

    Thank you very much in advance!

  3. Hey. I implemented your code, thank you very much, it seems to work pretty well! Only thing that didn‘t work from the start was: I was constantly shown as “not authenticated”. The problem were the serialize and unserialize methods of the User class. This answer at stackoverflow helped:

    http://stackoverflow.com/a/11903435

    I needed to add the username to the serialization/deserialization of both methods, now it works like a charm!

    1. When you say “not authenticated”, do you mean you seem to lose your authentication state and a new blank user is created within the DB (which you are sort of authenticated with)? This is happening with me and is driving me a little bit insane.

  4. There is no user provider for user “HWI\Bundle\OAuthBundle\Security\Core\User\OAuthUser

    Any ideas why I’m getting this error, User is correctly added to database, I get redirected as well, but I’m not authenticated…

  5. Hi Branko,
    i’m a beginner on symfony2, i need to create a facebook, google and twitter connection widh HWIOAuthBundle, i have installed FOSUserBundle and HWIOAuthBundle, but it doesn’t work even widh your explanation, this is my error:
    The target-entity My\UserBundle\Entity\Role cannot be found in ‘My\UserBundle\Entity\User#roles’.

    please help

    1. users = new ArrayCollection();
          }
      
          /**
           * Set role
           *
           * @param string $role
           *
           * @return Role
           */
          public function setRole($role)
          {
              $this->role = $role;
      
              return $this;
          }
      
          /**
           * Get role
           *
           * @return string
           */
          public function getRole()
          {
              return $this->role;
          }
          public function getUsers()
          {
              return $this->users->toArray();
          }
       
          public function getUsersAsCollection()
          {
              return $this->users;
          }
       
          public function setUsers($user)
          {
              return $this->users->add($user);
          }
          /**
           * Get id
           *
           * @return integer
           */
          public function getId()
          {
              return $this->id;
          }
      
      
      
          /**
           * Add user
           *
           * @param \AppBundle\Entity\User $user
           *
           * @return Role
           */
          public function addUser(\AppBundle\Entity\User $user)
          {
              $this->users[] = $user;
      
              return $this;
          }
      
          /**
           * Remove user
           *
           * @param \AppBundle\Entity\User $user
           */
          public function removeUser(\AppBundle\Entity\User $user)
          {
              $this->users->removeElement($user);
          }
      }
      
  6. Hi Branko,

    Its an awesome explanation. Mostly this should be in the documentation.

    I have a small problem,
    Can you please explain what does Entity\Role Contains?

    @ORM\ManyToMany(targetEntity=”Foggyline\Bundle\TickerBundle\Entity\Role”, inversedBy=”users”)

  7. This is an awesome post. Can I peak at your Entity\UserRepository? I’m in the process of ripping out FOSUserBundle in favor of this and I’m not entirely clear on what this should look like.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <blockquote cite=""> <code> <del datetime=""> <em> <s> <strike> <strong>. You may use following syntax for source code: <pre><code>$current = "Inchoo";</code></pre>.