🔥 What You Will Build
By the end of this tutorial, you will have:
✅ Facebook OAuth authentication
✅ Automatic user creation
✅ Facebook profile data storage
✅ Secure authentication flow
✅ Production-ready database structure
✅ Extendable setup (Google, GitHub, GitLab, etc.)
🧰 Requirements
Ensure the following are installed on your system:
PHP 8.2+
Laravel 12
MySQL / MariaDB
Composer
Facebook Developer Account
Step 1: Create Facebook OAuth Credentials
1.1 Facebook Developer Setup
Visit 👉 https://developers.facebook.com/
Click My Apps
Click Create App
Select Consumer
App Name:
Laravel Facebook LoginClick Create App
1.2 Add Facebook Login Product
Inside your app dashboard:
Click Add Product
Select Facebook Login
Choose Web
Configure URLs:
| Field | Value |
|---|---|
| Site URL | http://localhost:8000 |
| Valid OAuth Redirect URIs | https://localhost:8000/auth/facebook/callback |
1.3 Get Client Credentials
From Settings → Basic, copy:
App ID
App Secret
⚠️ Never expose your App Secret publicly
Step 2: Install Laravel Socialite
Laravel 12 supports auto-discovery, so no additional setup is required.
Step 3: Configure Facebook Service
📄 config/services.php
Step 4: Add Environment Variables
📄 .env
Step 5: Users Table (Multi-Provider Ready)
Your users table already supports OAuth providers.
Run migrations if needed:
Step 6: Create Facebook Authentication Controller
📄 app/Http/Controllers/Auth/FacebookAuthController.php
Step 7: Define Routes
📄 routes/web.php
Step 8: Add Facebook Login Button
📄 resources/views/auth/login.blade.php
Step 9: Protect Dashboard Route
Step 10: Run & Test
✅ Test Flow
Open the login page
Click Login with Facebook
Authorize the app
Redirected to dashboard 🎉
🔐 Security Best Practices
Use HTTPS in production
Handle missing Facebook emails
Limit OAuth scopes
Auto-assign user roles
Enable account linking
Log authentication failures
Verify Facebook app before production
🎯 Final Result
✅ Facebook OAuth fully integrated
✅ Automatic user creation
✅ Secure authentication flow
✅ Multi-provider ready
✅ Laravel 12 compatible
✅ Production-ready structure
📥 Full Source Code
👉 GitHub Repository
https://github.com/StarCodeKh/Login-with-Laravel-12-Using-Socialite

