GitHub Login allows users to authenticate quickly using their GitHub account without creating a traditional password.
In this tutorial, you’ll learn how to implement GitHub OAuth Login in Laravel 12 using Laravel Socialite with a clean, scalable, and production-ready database structure.
🔥 What You Will Build
By the end of this tutorial, you will have:
✅ GitHub OAuth Login
✅ Automatic user creation
✅ GitHub profile data storage
✅ Secure authentication flow
✅ Production-ready structure
✅ Extendable setup (Google, Facebook, GitLab, etc.)
🧰 Requirements
Make sure you have the following installed:
PHP 8.2+
Laravel 12
MySQL / MariaDB
Composer
GitHub Account
Step 1: Create GitHub OAuth Credentials
1.1 GitHub Developer Settings
Visit GitHub Developer Settings:
👉 https://github.com/settings/developers
Click OAuth Apps
Click New OAuth App
Fill in the required fields:
| Field | Value |
|---|---|
| Application name | Laravel GitHub Login |
| Homepage URL | http://127.0.0.1:8000 |
| Authorization callback URL | http://127.0.0.1:8000/auth/github/callback |
Click Register application
1.2 Get Client Credentials
After creating the app, copy:
Client ID
Client Secret
⚠️ Keep your Client Secret private!
Step 2: Install Laravel Socialite
Run the following command:
Laravel 12 supports package auto-discovery, so no manual provider registration is required.
Step 3: Configure GitHub Service
Open the services configuration file:
📄 config/services.php
Step 4: Add Environment Variables
Open your .env file and add:
Step 5: Create GitHub-Ready Users Table
Update your users table migration:
📄 database/migrations/create_users_table.php
Run the migration:
Step 6: Create GitHub Authentication Controller
Generate the controller:
📄 app/Http/Controllers/Auth/GithubAuthController.php
Step 7: Define Routes
📄 routes/web.php
Step 8: Add GitHub Login Button
📄 resources/views/auth/login.blade.php
Step 9: Protect Dashboard Route
Step 10: Run & Test the Application
✅ Test Flow
Open login page
Click Login with GitHub
Authorize GitHub access
Redirected to dashboard 🎉
🔐 Security Best Practices
Use HTTPS in production
Handle missing GitHub emails (private emails)
Limit OAuth scopes
Auto-assign roles
Enable account linking
Log authentication failures
🎯 Final Result
GitHub OAuth fully integrated
Automatic user creation
Secure login flow
Clean & scalable database
Laravel 12 compatible
Production-ready
📥 Download Full Source Code
👉 GitHub Repository
https://github.com/StarCodeKh/Login-with-Laravel-12-Using-Socialite

