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.

486 words
2 minutes
2025-09-15
#Laravel #Livewire #Tailwind CSS
Github

๐Ÿ” 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#

Laravel
Livewire
Tailwind CSS
SQLite
GitHub OAuth

๐Ÿ“‹ Installation & Setup#

Prerequisites#

Terminal window
- PHP >= 8.1
- Composer
- MySQL/PostgreSQL/SQLite
- Node.js & npm

Quick Start Guide#

  1. Clone the Repository
Terminal window
git clone https://github.com/mustafa-salah-1/laravel-socialite.git
cd laravel-socialite
  1. Install Dependencies
Terminal window
composer install
npm install
npm run dev
  1. Environment Configuration
Terminal window
cp .env.example .env
php artisan key:generate
  1. Database Setup
Terminal window
php artisan migrate
  1. Configure Social Providers

Google OAuth Setup#

  1. Create a project at Google Cloud Console
  2. Enable Google+ API
  3. Create OAuth 2.0 credentials
  4. Add authorized redirect URI: http://localhost:8000/auth/google/callback
  5. Update .env file:
GOOGLE_CLIENT_ID="your-google-client-id"
GOOGLE_CLIENT_SECRET="your-google-client-secret"

GitHub OAuth Setup#

  1. Create a new OAuth app at GitHub Developer Settings
  2. Set callback URL: http://localhost:8000/auth/github/callback
  3. Update .env file:
GITHUB_CLIENT_ID="your-github-client-id"
GITHUB_CLIENT_SECRET="your-github-client-secret"
  1. 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',
],
  1. Run the Application
Terminal window
php artisan serve

Visit http://localhost:8000 to see the application in action!

๐ŸŽฏ Technical Highlights#

OAuth Flow Implementation#

The application implements a secure OAuth 2.0 flow:

  1. User clicks โ€œSign in with Google/GitHubโ€
  2. Redirect to providerโ€™s authorization page
  3. User grants permission
  4. Provider redirects back with authorization code
  5. Exchange code for access token
  6. Retrieve user information
  7. Create or update user account
  8. 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 โ†’ Dashboard

Security Layers#

  1. OAuth 2.0 Protocol: Secure delegated access
  2. Laravel Authentication: Built-in security features
  3. HTTPS Enforcement: Encrypted data transmission (production)
  4. Token Encryption: Secure storage of sensitive data
  5. Rate Limiting: Prevent brute-force attacks

Extensibility#

The application is designed to easily add more OAuth providers:

  • Facebook
  • Twitter/X
  • LinkedIn
  • 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
Home Archive About
Profile Image of the Author
Mustafa Salah
Full-stack web developer
Categories
Tags