Today many sites use OAuth2 authentication, so that users can authenticate with their Google, Facebook, Microsoft, etc. Thus, the user allows giving access to his personal information already available on the social network to the website A.
For example : 'providers' => [ // a whole bunch of providers // remove 'Laravel\Socialite\SocialiteServiceProvider', \SocialiteProviders\Manager\ServiceProvider::class, // add ]; Exit fullscreen mode event-listener 3.
In https://laravel.com/docs/9.x/socialite, to authenticate users with an OAuth provider, you will need two routes : one for redirecting the user to the OAuth provider, and another for receving the callback from the provider after authentication : use Laravel\Socialite\Facades\Socialite; Route::get('/auth/redirect', function () { return Socialite::driver('github')->redirect(); }); Route::get('/auth/callback', function () { $user = Socialite::driver('github')->user(); // $user->token }); Exit fullscreen mode authentication-and-storage 6. When the user has been retrieved from the OAuth provider, you can determine if the user exits in your application’s database and authenticate the use.