Most of the sites require User login and registration with Social sites like Facebook, Google+, etc. Laravel provides a simple way to authenticate with OAuth provider Socialite. Laravel currently supports Facebook, Google, Twitter, GitHub, Bitbucket, etc.
Installing and configuring
composer require laravel/socialite
After installation, the Socialite package needs to add its credentials to service.php in the config folder.
'github' => [
'client_id' => env('Facebook_CLIENT_ID'),
'client_secret' => env('Facebook_CLIENT_SECRET'),
'redirect' => 'http://your-callback-url',
],
Also need to add socialite service and provide facade should register as like other packages use in Laravel, config/app.php
Routing for login with social
Here using two routes:
- Redirection the user to OAuth Provider
- Receiving the call from the provider after authentication.
Example for github Login with Socialite.
Using the different type of parameters which redirect the requests like with, use the Scope before redirecting the user, add some information, set the Scope to override all the existing scopes
Fetch the User detail
Retrieve the user information with the given token and store it to the database through the Laravel application.