Social Authentication
Complete guide to setting up social login with Google, GitHub, Facebook, Twitter/X, and LinkedIn in LaraDashboard.
Social Authentication
LaraDashboard supports social authentication using Laravel Socialite, allowing users to sign in or register using their social media accounts. This guide covers how to configure Google, GitHub, Facebook, Twitter/X, and LinkedIn authentication.
Overview
Social authentication provides:
- Seamless Registration - Users can sign up with one click
- Secure Login - No passwords to remember or manage
- Account Linking - Link multiple social accounts to one user
- Automatic Email Verification - Email is pre-verified from OAuth provider
Supported Providers
| Provider | Documentation | Developer Console |
|---|---|---|
| Google Identity Docs | Google Cloud Console | |
| GitHub | GitHub OAuth Docs | GitHub Developer Settings |
| Facebook Login Docs | Meta for Developers | |
| Twitter/X | Twitter OAuth 2.0 Docs | Twitter Developer Portal |
| LinkedIn OAuth Docs | LinkedIn Developer Portal |
Quick Start
Step 1: Enable Social Login
- Navigate to Admin → Settings → Authentication tab
- Scroll to Social Authentication section
- Enable Social Login toggle
Step 2: Configure a Provider
- Enable the provider (e.g., Google)
- Enter Client ID and Client Secret
- Copy the Callback URL shown
- Add the callback URL to your OAuth app settings
- Save settings
Step 3: Test
- Log out of admin panel
- Visit the login page
- Social login buttons should appear
- Click to test the flow
Provider Setup Guides
Create OAuth Credentials
- Go to Google Cloud Console
- Create a new project or select existing
- Click Create Credentials → OAuth client ID
- Select Web application
- Configure:
| Field | Value |
|---|---|
| Name | LaraDashboard (or your app name) |
| Authorized JavaScript origins | https://your-domain.com |
| Authorized redirect URIs | https://your-domain.com/auth/google/callback |
- Click Create
- Copy the Client ID and Client Secret
Configure OAuth Consent Screen
- Go to OAuth consent screen in Google Cloud Console
- Select External user type
- Fill in required fields:
- App name
- User support email
- Developer contact email
- Add scopes:
email,profile,openid - Add test users (while in testing mode)
- Submit for verification when ready for production
LaraDashboard Configuration
Option A: Admin Settings
Client ID: 123456789-xxxxxxxxxx.apps.googleusercontent.com
Client Secret: GOCSPX-xxxxxxxxxxxxxxxx
Option B: Environment Variables
GOOGLE_CLIENT_ID=123456789-xxxxxxxxxx.apps.googleusercontent.com
GOOGLE_CLIENT_SECRET=GOCSPX-xxxxxxxxxxxxxxxx
GitHub
Create OAuth App
- Go to GitHub Developer Settings
- Click OAuth Apps → New OAuth App
- Fill in the form:
| Field | Value |
|---|---|
| Application name | LaraDashboard |
| Homepage URL | https://your-domain.com |
| Authorization callback URL | https://your-domain.com/auth/github/callback |
- Click Register application
- Copy the Client ID
- Click Generate a new client secret
- Copy the Client Secret (shown only once!)
LaraDashboard Configuration
Option A: Admin Settings
Client ID: Iv1.xxxxxxxxxxxx
Client Secret: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Option B: Environment Variables
GITHUB_CLIENT_ID=Iv1.xxxxxxxxxxxx
GITHUB_CLIENT_SECRET=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Create Facebook App
- Go to Meta for Developers
- Click Create App
- Select Consumer or Business app type
- Enter app name and contact email
- Click Create App
Configure Facebook Login
- In your app dashboard, click Add Product
- Find Facebook Login and click Set Up
- Select Web
- Enter your site URL:
https://your-domain.com - Go to Facebook Login → Settings
- Add Valid OAuth Redirect URI:
https://your-domain.com/auth/facebook/callback - Save changes
Get Credentials
- Go to Settings → Basic
- Copy App ID (this is your Client ID)
- Click Show next to App Secret
- Copy App Secret (this is your Client Secret)
LaraDashboard Configuration
Option A: Admin Settings
Client ID: 1234567890123456
Client Secret: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Option B: Environment Variables
FACEBOOK_CLIENT_ID=1234567890123456
FACEBOOK_CLIENT_SECRET=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Note: Facebook requires app review for public access. During development, add test users in Roles → Test Users.
Twitter/X
Create Twitter App
- Go to Twitter Developer Portal
- Sign up for a developer account if needed
- Create a new Project and App
- In your app settings, click Set up under User authentication settings
- Configure:
| Field | Value |
|---|---|
| App permissions | Read (minimum) |
| Type of App | Web App |
| Callback URI | https://your-domain.com/auth/twitter/callback |
| Website URL | https://your-domain.com |
- Save changes
Get Credentials
- Go to Keys and tokens tab
- Under OAuth 2.0 Client ID and Client Secret:
- Copy Client ID
- Generate and copy Client Secret
LaraDashboard Configuration
Option A: Admin Settings
Client ID: xxxxxxxxxxxxxxxxxxxxxxxx
Client Secret: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Option B: Environment Variables
TWITTER_CLIENT_ID=xxxxxxxxxxxxxxxxxxxxxxxx
TWITTER_CLIENT_SECRET=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Note: Twitter requires a developer account with at least Basic access level.
Create LinkedIn App
- Go to LinkedIn Developer Portal
- Click Create app
- Fill in the form:
| Field | Value |
|---|---|
| App name | LaraDashboard |
| LinkedIn Page | Select or create a company page |
| App logo | Upload your logo |
- Click Create app
Configure OAuth Settings
- Go to Auth tab
- Under OAuth 2.0 settings, add Authorized redirect URL:
https://your-domain.com/auth/linkedin/callback - Click Update
Request Products
- Go to Products tab
- Request access to Sign In with LinkedIn using OpenID Connect
- Wait for approval (usually instant for Sign In)
Get Credentials
- Go to Auth tab
- Copy Client ID
- Click eye icon to reveal Client Secret
- Copy Client Secret
LaraDashboard Configuration
Option A: Admin Settings
Client ID: xxxxxxxxxxxx
Client Secret: xxxxxxxxxxxxxxxx
Option B: Environment Variables
LINKEDIN_CLIENT_ID=xxxxxxxxxxxx
LINKEDIN_CLIENT_SECRET=xxxxxxxxxxxxxxxx
Callback URLs Reference
Add these callback URLs to your OAuth app configurations:
| Provider | Callback URL |
|---|---|
https://your-domain.com/auth/google/callback |
|
| GitHub | https://your-domain.com/auth/github/callback |
https://your-domain.com/auth/facebook/callback |
|
| Twitter/X | https://your-domain.com/auth/twitter/callback |
https://your-domain.com/auth/linkedin/callback |
Important: Replace
your-domain.comwith your actual domain. Usehttp://localhost:8000for local development.
Configuration Methods
Method 1: Admin Settings (Recommended)
Configure credentials through the admin panel:
- Go to Settings → Authentication
- Enable Social Login
- Enable individual providers
- Enter credentials
- Save
Advantages:
- No code deployment needed
- Easy to update
- Encrypted storage in database
Method 2: Environment Variables
Add credentials to your .env file:
# Google
GOOGLE_CLIENT_ID=your-client-id
GOOGLE_CLIENT_SECRET=your-client-secret
# GitHub
GITHUB_CLIENT_ID=your-client-id
GITHUB_CLIENT_SECRET=your-client-secret
# Facebook
FACEBOOK_CLIENT_ID=your-client-id
FACEBOOK_CLIENT_SECRET=your-client-secret
# Twitter/X
TWITTER_CLIENT_ID=your-client-id
TWITTER_CLIENT_SECRET=your-client-secret
# LinkedIn
LINKEDIN_CLIENT_ID=your-client-id
LINKEDIN_CLIENT_SECRET=your-client-secret
Advantages:
- Version controlled (without actual values)
- Easy deployment configuration
- Works without database
Priority Order
Settings are loaded in this order (first found wins):
- Admin Settings (database)
- Environment Variables (
.env)
How It Works
User Flow
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ Login Page │────▶│ OAuth Provider │────▶│ LaraDashboard │
│ │ │ (Google, etc.) │ │ │
│ [Continue with │ │ │ │ User logged in │
│ Google] │ │ [Authorize] │ │ or registered │
└─────────────────┘ └──────────────────┘ └─────────────────┘
Account Behavior
| Scenario | Behavior |
|---|---|
| New user, new email | Creates new account, auto-verifies email |
| Existing user, same email | Links social account to existing user |
| Returning social user | Logs in directly |
Data Stored
For each social account:
- Provider name (google, github, etc.)
- Provider user ID
- Email from provider
- Avatar URL
- Access/refresh tokens (encrypted)
Customization
Adding Social Buttons Elsewhere
Use the Blade component anywhere:
<x-auth.social-login-buttons />
{{-- With custom divider text --}}
<x-auth.social-login-buttons divider-text="Or sign up with" />
Extending with Hooks
Add custom logic using hooks:
use App\Enums\Hooks\AuthFilterHook;
use App\Support\Facades\Hook;
// Modify available providers
Hook::addFilter(AuthFilterHook::AUTH_SOCIAL_LOGIN_PROVIDERS, function ($providers) {
// Remove Facebook
unset($providers['facebook']);
return $providers;
});
Custom Redirect After Login
use App\Enums\Hooks\AuthFilterHook;
use App\Support\Facades\Hook;
Hook::addFilter(AuthFilterHook::LOGIN_REDIRECT_PATH, function ($path) {
// Custom redirect for social logins
if (session('social_login')) {
return '/welcome';
}
return $path;
});
Security Considerations
Best Practices
- Use HTTPS - OAuth requires secure connections in production
- Verify Domains - Only add your actual domains to OAuth apps
- Rotate Secrets - Periodically regenerate client secrets
- Review Permissions - Request only necessary OAuth scopes
- Monitor Access - Review connected apps in provider dashboards
Token Storage
- Access tokens are encrypted at rest
- Tokens are refreshed automatically when possible
- Expired tokens are updated on next login
Rate Limiting
Social login routes are rate-limited to prevent abuse:
- Max 20 attempts per minute per IP
Troubleshooting
Common Issues
"redirect_uri_mismatch" Error
Cause: Callback URL doesn't match OAuth app configuration
Solution:
- Copy the exact callback URL from LaraDashboard settings
- Add it to your OAuth app's authorized redirect URIs
- Ensure protocol matches (http vs https)
- Check for trailing slashes
"invalid_client" Error
Cause: Wrong Client ID or Client Secret
Solution:
- Regenerate credentials in provider console
- Update in LaraDashboard settings
- Clear config cache:
php artisan config:clear
Social Buttons Not Showing
Cause: Social login not enabled or no providers configured
Solution:
- Enable Social Login toggle in settings
- Enable at least one provider
- Enter valid credentials
- Clear view cache:
php artisan view:clear
"User cancelled" or "Access denied"
Cause: User declined OAuth permissions
Solution: This is expected behavior. User chose not to authorize.
Facebook: "App Not Setup"
Cause: Facebook app in development mode
Solution:
- Add test users in Facebook app settings
- Or submit app for review for public access
Twitter: "Something went wrong"
Cause: Incorrect OAuth version or permissions
Solution:
- Ensure OAuth 2.0 is enabled
- Verify User Authentication Settings are configured
- Check API access level (Basic or higher)
Debug Mode
Enable debug mode temporarily to see detailed errors:
APP_DEBUG=true
Check Laravel logs at storage/logs/laravel.log for detailed error messages.
Database Schema
Social accounts are stored in the social_accounts table:
| Column | Type | Description |
|---|---|---|
id |
bigint | Primary key |
user_id |
bigint | Foreign key to users |
provider |
string | Provider name (google, github, etc.) |
provider_user_id |
string | User ID from provider |
provider_email |
string | Email from provider |
provider_avatar |
string | Avatar URL from provider |
access_token |
text | Encrypted access token |
refresh_token |
text | Encrypted refresh token |
token_expires_at |
timestamp | Token expiry time |
created_at |
timestamp | Creation timestamp |
updated_at |
timestamp | Last update timestamp |
Related Documentation
- Settings Guide - General settings configuration
- User Management - Managing users and roles
- API Authentication - API token authentication
- Hooks Reference - Extending functionality
Quick Reference
Developer Console Links
| Provider | Console URL |
|---|---|
| console.cloud.google.com/apis/credentials | |
| GitHub | github.com/settings/developers |
| developers.facebook.com/apps | |
| Twitter/X | developer.twitter.com/en/portal/dashboard |
| linkedin.com/developers/apps |
Environment Variables
# Enable all providers via .env
GOOGLE_CLIENT_ID=xxx
GOOGLE_CLIENT_SECRET=xxx
GITHUB_CLIENT_ID=xxx
GITHUB_CLIENT_SECRET=xxx
FACEBOOK_CLIENT_ID=xxx
FACEBOOK_CLIENT_SECRET=xxx
TWITTER_CLIENT_ID=xxx
TWITTER_CLIENT_SECRET=xxx
LINKEDIN_CLIENT_ID=xxx
LINKEDIN_CLIENT_SECRET=xxx