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_providerin thesecurity.ymlwith your custom created service
Here are the steps:
- Routing. In
routing.ymlI have added all the routes for both bundles. - Configuration. I have set the
config.ymlmostly as it is presented in the HWIOAuthBundle. - Security. I have set the
security.ymlmostly as it is presented in the HWIOAuthBundle (though my routes are using/loginpattern, not/connect). Also, theoauth_user_provideris 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($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/facebookorhttp://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/facebookorhttp://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 :).