I have managed to install this… and make it work. I implemented it for Facebook and Google, but you can extend it. My solution it is mostly as described in #116, with a bit of more code presented. The key aspects that lack in the #116 presentation (IMO) are:
- the registration as service of your custom FOSUBUserProvider (with the necessary parameters)
- set the service for
oauth_user_provider
in thesecurity.yml
with your custom created service
Here are the steps:
- Routing. In
routing.yml
I have added all the routes for both bundles. - Configuration. I have set the
config.yml
mostly as it is presented in the HWIOAuthBundle. - Security. I have set the
security.yml
mostly as it is presented in the HWIOAuthBundle (though my routes are using/login
pattern, not/connect
). Also, theoauth_user_provider
is set for my custom service. - User. My own User entity, extended from FosUser.
- UserProvider. My user provider, registered as service, extended from FOSUBUserProvider. This is the one that actually does the User registration in YOUR database with data from PROVIDERS (Facebook, Google, etc.) and in responsible for connecting already logged in users with accounts from PROVIDERS. It does this by overvriting 2 functions (
connect(UserInterface $user, UserResponseInterface $response)
andloadUserByOAuthUserResponse(UserResponseInterface $response)
). See code below. - Custom service. My user provider is registered as service.
Using this code, when:
- No user is authenticated on my site: by accessing
http://my_app_web_root/login/facebook
orhttp://my_app_web_root/login/google
, a user is created in my database (with data as it is saved in the custom FOSUBUserProvider) and it is automatically login-ed to my site. - A user is authenticated on my site: by accessing
http://my_app_web_root/login/facebook
orhttp://my_app_web_root/login/google
, the current user is updated with data from the provider (account linking).
I think this is the behavior everybody was expecting :).