UPDATE:
I tried using this code in one of my recent projects, and it no longer worked. The reason is because HWIOAuthBundle has updated several times, and the configuration files do not match. I put the code above, and also registered on several other social networks on github, which you can find in HWIOAuthBundleByExample .
I have a week of experience with symfony2, and in recent days I have been working on myself. Found your question today (when I was still studying).
I am going to present to you what I needed to do based on the data and how I did it. After that, I will try to give you some key links, and I hope that you will be able to model them for your needs.
My apps need a Facebook account and an ADMIN role. Because there will be only a few administrators, I only need a few Facebook IDs for authentication, so I store them in a yaml array. (See At the end, how you can load them from the database).
Here is what I did:
So, you can pretty much see that when a request to enter facebook comes in, I do a database check (based on the facebook graph id) and add it if necessary. In addition, I set some things in the sessions (you wonβt need it), and after that I also have to return the HWI \ Bundle \ OAuthBundle \ Security \ Core \ User \ OAuthUser object (this is where sf2 gets its roles). Therefore, I am expanding it (thus, I have access to $ isAdmin). As you said, you need roles for each user, and you must also edit them. To do this, you can implement getRoles () using ManyToMany relationships (provide access to the doctinary entityManager through the constructor). You can see what applies here: http://symfony.com/doc/current/cookbook/security/entity_provider.html#managing-roles-in-the-database .
As I said, you have to configure it a lot (my only application is to enter facebook only and with access as access in the form of help in_memory), but I would like for me to have such code when I started. So I really hope this helps you. Ask your questions, if any.
source share