Laravel Socialite Authentication
A comprehensive Laravel application implementing OAuth authentication with Google and GitHub using Laravel Socialite and Livewire starter kit for seamless social login experience.
๐ Project Overview
Laravel Socialite Authentication is a modern authentication application that demonstrates the implementation of OAuth 2.0 social login functionality. Built with Laravelโs powerful Socialite package and Livewire starter kit, this project provides users with a seamless and secure way to authenticate using their existing Google and GitHub accounts.
The application eliminates the friction of traditional registration forms by allowing users to sign in with just a few clicks using their preferred social platform, while maintaining robust security and data integrity.
๐ Key Features
Social Authentication
- Google OAuth Integration: Sign in with Google accounts
- GitHub OAuth Integration: Authenticate using GitHub credentials
- Seamless User Experience: One-click social login
- Account Linking: Connect multiple social accounts to a single user profile
Built-in Authentication System
- Livewire Starter Kit: Laravelโs official authentication scaffolding
- User Registration: Traditional email/password registration option
- Login System: Secure authentication with session management
- Profile Management: Update user information and preferences
- Password Reset: Email-based password recovery
Security Features
- OAuth 2.0 Protocol: Industry-standard authentication
- CSRF Protection: Cross-site request forgery prevention
- Secure Token Handling: Safe storage of access tokens
- Session Security: Protected user sessions
- Email Verification: Optional email confirmation
๐ ๏ธ Technologies Used
๐ Installation & Setup
Prerequisites
- PHP >= 8.1- Composer- MySQL/PostgreSQL/SQLite- Node.js & npmQuick Start Guide
- Clone the Repository
git clone https://github.com/mustafa-salah-1/laravel-socialite.gitcd laravel-socialite- Install Dependencies
composer installnpm installnpm run dev- Environment Configuration
cp .env.example .envphp artisan key:generate- Database Setup
php artisan migrate- Configure Social Providers
Google OAuth Setup
- Create a project at Google Cloud Console
- Enable Google+ API
- Create OAuth 2.0 credentials
- Add authorized redirect URI:
http://localhost:8000/auth/google/callback - Update
.envfile:
GOOGLE_CLIENT_ID="your-google-client-id"GOOGLE_CLIENT_SECRET="your-google-client-secret"GitHub OAuth Setup
- Create a new OAuth app at GitHub Developer Settings
- Set callback URL:
http://localhost:8000/auth/github/callback - Update
.envfile:
GITHUB_CLIENT_ID="your-github-client-id"GITHUB_CLIENT_SECRET="your-github-client-secret"- Configure Services
Add to config/services.php:
'github' => [ 'client_id' => env('GITHUB_CLIENT_ID'), 'client_secret' => env('GITHUB_CLIENT_SECRET'), 'redirect' => 'http://localhost:8000/auth/github/callback',],
'google' => [ 'client_id' => env('GOOGLE_CLIENT_ID'), 'client_secret' => env('GOOGLE_CLIENT_SECRET'), 'redirect' => 'http://localhost:8000/auth/google/callback',],- Run the Application
php artisan serveVisit http://localhost:8000 to see the application in action!
๐ฏ Technical Highlights
OAuth Flow Implementation
The application implements a secure OAuth 2.0 flow:
- User clicks โSign in with Google/GitHubโ
- Redirect to providerโs authorization page
- User grants permission
- Provider redirects back with authorization code
- Exchange code for access token
- Retrieve user information
- Create or update user account
- Authenticate user session
Database Schema
User table includes:
- Traditional fields (name, email, password)
- Social authentication fields (provider, provider_id)
- Timestamps and email verification status
๐ Live Demo
Explore the source code: GitHub Repository
๐จ User Interface
Login Page Features
- Clean and modern design
- Social login buttons (Google & GitHub)
- Traditional email/password form
- โRemember meโ functionality
- Forgot password link
- Registration link
Registration Page
- User-friendly form layout
- Email validation
- Password strength indicators
- Agree to terms checkbox
- Alternative social registration
Profile Management
- Update personal information
- Change password
- Connected social accounts
- Account security settings
๐ง Technical Architecture
Authentication Flow
User Request โ Social Provider โ Callback โ Socialite Handlerโ User Creation/Update โ Session Creation โ DashboardSecurity Layers
- OAuth 2.0 Protocol: Secure delegated access
- Laravel Authentication: Built-in security features
- HTTPS Enforcement: Encrypted data transmission (production)
- Token Encryption: Secure storage of sensitive data
- Rate Limiting: Prevent brute-force attacks
Extensibility
The application is designed to easily add more OAuth providers:
- Twitter/X
- Microsoft
- Apple
๐ Learning Outcomes
This project demonstrates proficiency in:
- OAuth 2.0 authentication protocol
- Laravel Socialite package implementation
- Livewire component development
- Secure user data handling
- Third-party API integration
- Modern authentication best practices
- Database design for social authentication