Laravel設定
1. 安裝Socialite:
在之前的google第三方登入文章有提到,不再贅述。
2. .env新增:
FB_CLIENT_ID=xxx
FB_CLIENT_SECRET=xxx
FB_REDIRECT=http://yourdomain/facebook/authCallback
3. config/services.php新增:
'facebook' = [ 'client_id' = env('FB_CLIENT_ID'), 'client_secret' = env('FB_CLIENT_SECRET'), 'redirect' = env('FB_REDIRECT'),
]
4. config/app.php providers新增:
Laravel\Socialite\SocialiteServiceProvider::class,
5. config/app.php aliases新增:
'Socialite' = Laravel\Socialite\SocialiteServiceProvider::class,
6. route/web.php新增:
Route::get('/facebook/auth', [FBSocialiteController::class, 'fbLogin']);
Route::get('/facebook/authCallback', [FBSocialiteController::class, 'fbLoginCallback']);