Follow this guide to get your ID and Secret for your oauth providers.
Set all secrets and ids in .env.local (not commited) and in the vault.
Configure the firewall:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# config/packages/security.yamlsecurity:firewalls:your_firewall_name:# ...oauth:resource_owners:facebook:"/fr/login/check-facebook"linkedin:"/fr/login/check-linkedin"google:"/fr/login/check-google"login_path:your_login_route_namecheck_path:your_login_check_route_nameuse_forward:falsefailure_path:your_failure_route_name# could be login routeoauth_user_provider:service:App\Infras\Security\Provider\OauthUserProvider
We use the oauth login for both authentication and register processes. If the user exists in our database, we authenticate them. If the user does not exist, we create them.
Use these links to start oauth authentication process.
1
2
3
<a href="{{path('hwi_oauth_service_redirect',{service:'google'})}}">Authenticate with Google</a><a href="{{path('hwi_oauth_service_redirect',{service:'facebook'})}}">Authenticate with Facebook</a><a href="{{path('hwi_oauth_service_redirect',{service:'linkedin'})}}">Authenticate with Linkedin</a>
You can use the same links for register.
1
2
3
<a href="{{path('hwi_oauth_service_redirect',{service:'google'})}}">Register with Google</a><a href="{{path('hwi_oauth_service_redirect',{service:'facebook'})}}">Register with Facebook</a><a href="{{path('hwi_oauth_service_redirect',{service:'linkedin'})}}">Register with Linkedin</a>