A while ago I have written a GIST on how to integrate these using Symfony 2.4. Some time have passsed and I needed to use them in a Symfony 3.4 (with Flex) ... and I had some hard times porting everything. So, in order to provide some help for you out there... here is the way I have done it:
First of all, I had some troubles installing HWIOAuthBundle. This is the solution that worked for me. On and on, you will NOT be able to install it without errors UNTIL you set up the propper configs for the bundle.
After everything was installed and running (I will not insist here on setting up FosUserBundle, as that is pretty easy and goes smoothly), we should start and setup all the proper settings.
In this demo I have used Facebook and GitHub, but you may add any other providers.
You will get some of the config automatically setup when installing bundles, but you need to focus on:
- .env file - here we will store the AppId and Secret for FB and Github (and any other providers you may use)
- hwi_oauth.yaml file, from
config/packages
- some configuration you will already find there after installing the bundle itself, but below you will find the complete setup for it - security.yaml file, from
config/packages
- this is where we tell Symfony how to handle security/login, setup the firewall and secure the application a bit - hwi_oauth_routing.yaml file, from
config/routing
- The key aspect (which gave ma a serious time wasting until figuring out) is to put the callback URLs (facebook_login
andgithub_login
) as first in the file. The other routs will already be placed there from when installing the bundle itself - Register your custom FOSUBUserProvider as service - this is done in the services.yaml file from
config
folder - Configure your User class with the appropriate data members to store the data from providers
- Use the links to connect - see example.twig below
Beside my original GIST and the official documentations I have used this article as inspiration. You may use it to add other providers.