Download the PHP package emmanuel-saleem/social-auth without Composer
On this page you can find all versions of the php package emmanuel-saleem/social-auth. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download emmanuel-saleem/social-auth
More information about emmanuel-saleem/social-auth
Files in emmanuel-saleem/social-auth
Package social-auth
Short Description Laravel social authentication package with Google, Microsoft and more OAuth providers using Socialite
License MIT
Informations about the package social-auth
Emmanuel Saleem Social Auth Package
A comprehensive Laravel package for OAuth social authentication with Google and Microsoft, supporting both traditional web applications and modern SPA/API-based frontends.
๐ Table of Contents
- Features
- Requirements
- Installation
- Quick Start - Add Login to Your App โญ
- Configuration
- Usage (Web & API)
- Customization
- Troubleshooting
- Documentation
โจ Features
- ๐ Google OAuth authentication (Web & API)
- ๐ Microsoft OAuth authentication (Web & API)
- ๐ Dual Mode Support: Traditional web and SPA/API applications
- ๐จ Pre-built Login UI with beautiful, modern design
- ๐ฑ Mobile-friendly responsive design
- ๐ Auto-migration for adding social auth fields to users table
- ๐ก๏ธ Flexible Authentication: Support for both Laravel Sanctum and Laravel Passport
- ๐ Token Management: Automatic token generation with expiration support
- ๐ฆ Easy Installation with Laravel auto-discovery
- โ๏ธ Highly Configurable: routes, middleware, redirects, button labels, and more
- ๐ Production Ready with comprehensive error handling
- ๐ Standardized API Responses with consistent JSON format
๐ Requirements
- PHP 8.0 or higher
- Laravel 8.x, 9.x, 10.x or 11.x
- Laravel Socialite 4.x (for Laravel 8) or 5.x (for Laravel 9+)
- Laravel Sanctum (for API authentication - default) OR Laravel Passport (optional)
๐ฆ Installation
Step 1: Install via Composer
For Development (Current Available Version):
Alternative Installation Methods:
๐ Note: The package is currently in development. Stable versions will be available after publishing to Packagist. Use
dev-masterfor now.
Step 2: Install Authentication System (for API routes)
Option A: Laravel Sanctum (Recommended - Default)
Option B: Laravel Passport (For OAuth2 Server)
๐ See PASSPORT_SETUP.md for detailed Passport configuration
Step 3: Add HasApiTokens to User Model
For Sanctum (Default):
For Passport:
Then configure the driver in .env:
Step 4: Publish Package Assets
โ๏ธ Configuration
Environment Variables
Add these to your .env file:
Update config/services.php
Add OAuth provider configurations:
OAuth Provider Setup
Google Cloud Console
Follow these steps to create OAuth credentials:
Step 1: Go to Google Cloud Console
Step 2: Create a new project or select an existing one
Step 3: Navigate to "APIs & Services" โ "Credentials"
Step 4: Click "CREATE CREDENTIALS" โ Select "OAuth client ID"
Step 5: Configure the OAuth consent screen (if first time)
Step 6: Select "Web application" as the application type
Step 7: Add your application name and authorized redirect URIs:
Authorized redirect URIs:
- For Web:
http://localhost:8000/emmanuel-saleem/social-auth/google/callback - For API/SPA:
http://localhost:3000/auth/google/callback - For Production:
https://yourdomain.com/emmanuel-saleem/social-auth/google/callback
Step 8: Click "CREATE" and you'll receive your credentials
Step 9: Copy the Client ID and Client Secret to your .env file
Step 10: Enable required APIs (Google+ API or People API)
โ
Configuration Complete! Now add the credentials to your .env file:
Microsoft Azure Portal
Follow these detailed steps to set up Microsoft OAuth authentication:
Step 1: Access Azure Portal
- Go to Azure Portal
- Sign in with your Microsoft account
Step 2: Navigate to App Registrations
- In the Azure portal, search for "App registrations" in the search bar
- Click on "App registrations" from the search results
Step 3: Create New App Registration
- Click "New registration" button
- Fill in the application details:
- Name: Enter your application name (e.g., "Laravel Social Auth")
- Supported account types: Choose based on your needs:
- "Personal Microsoft accounts only" - for consumer apps
- "Accounts in any organizational directory and personal Microsoft accounts" - for broader access
- Redirect URI: Add your callback URL:
- Web:
http://localhost:8000/emmanuel-saleem/social-auth/microsoft/callback - API:
http://localhost:3000/auth/microsoft/callback
- Web:
Step 4: Configure Authentication
- After creating the app, go to "Authentication" in the left menu
- Add your redirect URIs:
http://localhost:8000/emmanuel-saleem/social-auth/microsoft/callbackhttps://yourdomain.com/emmanuel-saleem/social-auth/microsoft/callback(for production)
Step 5: Create Client Secret
- Go to "Certificates & secrets" in the left menu
- Click "New client secret"
- Add a description and choose expiration period
- Important: Copy the secret value immediately (it won't be shown again)
Step 6: Configure API Permissions
- Go to "API permissions" in the left menu
- Click "Add a permission"
- Select "Microsoft Graph"
- Choose "Delegated permissions"
- Add these permissions:
openidprofileemailUser.Readoffline_access
Step 7: Grant Admin Consent
- Click "Grant admin consent" button
- Confirm the permissions
Step 8: Get Your Credentials
- Go to "Overview" in the left menu
- Copy the following values:
- Application (client) ID
- Directory (tenant) ID (if using specific tenant)
Step 9: Update Your .env File
Add the Microsoft credentials to your .env file:
Important Notes:
- For Personal Microsoft accounts only, use
MICROSOFT_TENANT_ID=consumers - For All account types, you can use
MICROSOFT_TENANT_ID=commonor leave it empty - Make sure your redirect URI matches exactly what you configured in Azure
- The client secret expires based on your chosen expiration period
๐ Quick Start - Add Login to Your App
How to Add Google & Microsoft Login
After installation, you have 3 easy ways to add social login to your application:
Method 1: Use the Pre-built Login Page (Easiest)
Simply redirect users to the package's built-in login page:
Visit: http://localhost:8000/emmanuel-saleem/social-auth/login
The page will show beautiful Google and Microsoft login buttons automatically! โจ
Method 2: Include the Component in Your Own Page
Add the social auth buttons to any existing page:
That's it! Both Google and Microsoft buttons will appear with icons and proper styling.
Method 3: Create Your Own Custom Buttons
Use the package routes directly for full customization:
Logout Button
Add a logout button anywhere in your app:
๐ฏ What Happens After Login?
- User clicks "Sign in with Google" or "Sign in with Microsoft"
- Redirects to Google/Microsoft for authentication
- User approves the login request
- Redirects back to your app with user data
- Package automatically:
- Creates a new user (if doesn't exist)
- Updates existing user info
- Logs them in
- Redirects to dashboard (configurable)
User is now logged in! ๐
Access logged-in user anywhere:
๐ Complete Web Integration Guide
Step-by-Step: Add Social Login to Your Laravel Web App
Step 1: Create Your Login Page
Create or update your login blade file at resources/views/auth/login.blade.php:
Step 2: Create a Route for Login Page
Add to routes/web.php:
Step 3: Update Your Welcome Page (Optional)
Add a login button to resources/views/welcome.blade.php:
Step 4: Create a Dashboard Page
Create resources/views/dashboard.blade.php:
Step 5: Add Dashboard Route
Add to routes/web.php:
๐งช Testing Your Social Login
Test 1: Visit Login Page
Expected Result:
- โ See a beautiful login page
- โ Two buttons: "Continue with Google" and "Continue with Microsoft"
- โ Buttons have official brand colors and icons
Test 2: Click "Continue with Google"
What Happens:
- Redirects to Google login page
- Google asks for permission
- You approve
- Redirects back to your app
- Package creates/updates user
- Logs you in automatically
- Redirects to
/dashboard(configurable)
Check Database:
Test 3: Check User Data in Dashboard
Visit: http://localhost:8000/dashboard
Expected Result:
- โ See welcome message with your name
- โ See your Google profile picture
- โ See your email
- โ See "Google OAuth" as login method
- โ See Google ID
Test 4: Test Logout
Click the "Logout" button
Expected Result:
- โ Logged out successfully
- โ Redirected to home page
- โ
Can't access
/dashboardanymore
Test 5: Test Microsoft Login
Follow same steps but click "Continue with Microsoft"
Expected Result:
- โ Redirects to Microsoft login
- โ User created with microsoft_id
- โ Redirected to dashboard
๐ Debugging & Verification
Check Routes Are Loaded
Expected Output:
Check Database Table
Should show the social auth migration as completed.
Should show columns:
google_idmicrosoft_idavatargoogle_tokengoogle_refresh_tokenmicrosoft_tokenmicrosoft_refresh_token
Check Logged-in User
In any controller or view:
๐ธ Quick Test Checklist
- [ ] Login page displays correctly
- [ ] Google button works and redirects
- [ ] Microsoft button works and redirects
- [ ] User is created in database
- [ ] User data (name, email, avatar) is saved
- [ ] User is automatically logged in
- [ ] Dashboard shows user info
- [ ] Logout works correctly
- [ ] Can login again after logout
- [ ] Avatar/profile picture displays
๐จ Customize Redirect After Login
In .env file:
Or in config/emmanuel-saleem-social-auth.php:
๐ Usage
Option 1: Traditional Web Application
Routes Available
The package automatically registers these web routes:
Implementation
Option A: Use the built-in login page
Simply redirect users to the login page:
Option B: Include the component in your own page
The package provides a reusable Blade component that you can include anywhere:
Option C: Use individual buttons
Logout
Option 2: API / SPA Application (React, Vue, Next.js)
For modern frontend applications, use the API endpoints.
Frontend Login Flow
Step 1: User clicks "Sign in with Google" button
Step 2: Get the OAuth URL from backend:
Step 3: Handle the callback when user returns:
Step 4: Use the token for authenticated requests:
For complete React/Vue examples, see USAGE_EXAMPLES.md
Next.js example pages
Add these pages to your Next.js app for a quick end-to-end test with this package's API endpoints.
app/(public)/auth/google/callback/page.tsx
app/(public)/oauth-test/page.tsx
API Routes Available
Quick Start Example (React)
๐ For complete API integration guide, see OAUTH_API_GUIDE.md
๐ก API Response Format
All API endpoints return standardized JSON responses:
Success Response
Error Response
๐จ Customization
Customize Button Labels
You can customize the button text via .env file:
Or in the config file config/emmanuel-saleem-social-auth.php:
Customize Footer
Hide the footer:
Or customize the footer text:
In config file:
Customize Routes Prefix
Edit config/emmanuel-saleem-social-auth.php:
Customize Redirects
Customize Middleware
Customize Views
After publishing views:
Edit the views in resources/views/vendor/emmanuel-saleem-social-auth/
The component includes:
- โ Both Google and Microsoft buttons with official icons
- โ Responsive design (mobile-friendly)
- โ Error/success message display
- โ Modern, clean UI
- โ Inline CSS (no external dependencies)
- โ Customizable labels and footer
- โ Can be included in any existing page
๐๏ธ Database Schema
The package adds these fields to your users table:
| Column | Type | Description |
|---|---|---|
google_id |
string | Google user ID |
microsoft_id |
string | Microsoft user ID |
avatar |
string | Profile picture URL |
google_token |
text | Google access token |
google_refresh_token |
text | Google refresh token |
microsoft_token |
text | Microsoft access token |
microsoft_refresh_token |
text | Microsoft refresh token |
The password column is also made nullable to support social-only users.
๐ Security
- All OAuth tokens are stored securely in the database
- Passwords for OAuth users are randomly generated and hashed
- Email verification is automatically marked as verified for OAuth users
- CSRF protection on all web routes
- Stateless OAuth for API routes
๐งช Testing
Test Web Routes
Test API Routes
๐ Troubleshooting
Issue: Package installs as dev-master instead of stable version
Problem:
When running composer require emmanuel-saleem/social-auth, it installs dev-master instead of a stable version.
Solution:
-
Specify version constraint explicitly:
-
Or install specific version:
- Check your composer.json minimum-stability:
Issue: Composer cache directory not writable (Docker)
Problem:
Solution: Run composer with proper permissions or disable cache:
Issue: Laravel version conflict
Problem:
Solution: The package supports Laravel 9, 10, and 11. Check your Laravel version:
If you're on Laravel 8 or below, you need to upgrade Laravel or use an older version of Socialite.
Issue: "Class not found" error
Solution: Make sure to run composer dump-autoload
Issue: Microsoft OAuth "invalid_client" error
Problem:
Solution:
-
Check your credentials in
.envfile: -
Verify in Azure Portal:
- Go to your app registration โ Overview
- Copy the exact Application (client) ID
- Go to Certificates & secrets โ Copy the exact client secret
- Clear config cache:
Issue: Microsoft OAuth "userAudience" configuration error
Problem:
Solution:
This happens when your Azure app is configured for "Personal Microsoft accounts only" but the OAuth request uses the /common endpoint.
Option 1: Change Azure App Configuration (Recommended)
- Go to Azure Portal โ Your App Registration โ Authentication
- Change "Supported account types" to "Accounts in any organizational directory and personal Microsoft accounts"
- This allows the
/commonendpoint to work
Option 2: Use Consumer Endpoint
- Keep "Personal Microsoft accounts only" in Azure
-
Set in your
.env: - Clear config cache:
Issue: Role dropdown not saving selected value
Problem: The role selected from the dropdown is not being saved to the database.
Solution: This was fixed in the latest version. Make sure you're using the updated package and clear caches:
The package now properly merges form data in the correct order: payload โ user_defaults โ extra (where extra overrides defaults).
Issue: Routes not working
Solution: Clear route cache:
Issue: "redirect_uri_mismatch"
Solution: Ensure your redirect URIs in .env match exactly with those in Google/Microsoft console
Issue: Token creation fails
Solution: Make sure:
- Laravel Sanctum is installed
- User model has
HasApiTokenstrait - Migrations have run
Issue: CORS errors in API
Solution: Configure CORS in config/cors.php:
๐ Documentation
- API Integration Guide - Complete guide for SPA/API integration
- Passport Setup Guide - Laravel Passport integration
- Usage Examples - Practical examples for React, Vue, etc.
- Laravel Socialite Docs
- Laravel Sanctum Docs
- Laravel Passport Docs
๐ฃ๏ธ Roadmap
- [x] Google OAuth support
- [x] Microsoft OAuth support
- [x] API endpoints for SPA
- [x] Standardized response format
- [ ] GitHub OAuth support
- [ ] Facebook OAuth support
- [ ] LinkedIn OAuth support
- [ ] Twitter/X OAuth support
- [ ] Two-factor authentication
- [ ] Social account linking
- [ ] Admin panel for managing OAuth apps
๐ค Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
๐ License
This package is open-sourced software licensed under the MIT license.
๐จโ๐ป Author
Emmanuel Saleem
- Email: [email protected]
- LinkedIn: linkedin.com/in/es77
- GitHub: @emmanuel-saleem
๐ Acknowledgments
- Laravel Socialite team
- Laravel Sanctum team
- All contributors
๐ Support
If you encounter any issues or have questions:
- Check the OAUTH_API_GUIDE.md
- Review Troubleshooting section
- Check existing GitHub Issues
- Create a new issue with detailed information
Made with โค๏ธ for the Laravel community dodcumeiton link mirsoft https://learn.microsoft.com/en-us/graph/auth-register-app-v2
All versions of social-auth with dependencies
laravel/framework Version ^8.0|^9.0|^10.0|^11.0
laravel/socialite Version ^4.4|^5.0
socialiteproviders/microsoft Version ^4.0