Installation:
composer require chrisreedio/socialment
php artisan socialment:install
Add to Panel:
In app/Providers/Filament/AdminPanelProvider.php:
$panel->plugins([
\ChrisReedIO\Socialment\SocialmentPlugin::make()
->registerProvider('github', 'fab-github', 'GitHub'),
]);
Configure Services:
Add provider credentials to config/services.php (e.g., GitHub example):
'github' => [
'client_id' => env('GITHUB_CLIENT_ID'),
'client_secret' => env('GITHUB_CLIENT_SECRET'),
'redirect' => env('GITHUB_REDIRECT_URI'),
],
Add Styling:
Edit your panel's theme.css:
@source '../../../../vendor/chrisreedio/socialment/resources';
Enable GitHub OAuth login for your Filament admin panel with a single button. Users can now log in via GitHub without managing traditional credentials.
Provider Registration: Register providers in your panel configuration with icon and label:
->registerProvider('google', 'fab-google', 'Google')
->registerProvider('azure', 'fab-microsoft', 'Azure AD')
Login Flow:
/login/{provider}/callback.Custom User Logic:
Use createUser closure to customize user creation:
->createUser(function (ConnectedAccount $account) {
return User::firstOrCreate(
['email' => $account->userEmail],
['name' => $account->userName]
);
})
SocialmentPlugin in each panel provider.->visible(fn () => Auth::check() === false)
->registerProvider('azure', 'fab-microsoft', 'Azure AD', [
'scopes' => ['User.Read', 'openid', 'profile'],
])
For shared auth between Filament and SPA:
Route::spaAuth('dashboard');
'paths' => ['spa/*'],
'supports_credentials' => true,
Missing Styling:
Forgetting to add @source in theme.css will hide provider buttons.
Fix: Always include:
@source '../../../../vendor/chrisreedio/socialment/resources';
Redirect URI Mismatch:
Ensure redirect in config/services.php matches the callback URL pattern:
https://yourdomain.com/login/{provider}/callback.
Debug: Check .env for correct APP_URL and provider-specific URIs.
User Model Conflicts:
Socialment expects a default User model. Override in config/socialment.php:
'models' => [
'user' => \App\Models\CustomUser::class,
],
Stateful Sessions:
For SPA auth, ensure SESSION_DOMAIN starts with a dot (e.g., .localhost) and matches both frontend/backend domains.
Failed Logins:
Check storage/logs/laravel.log for Socialite errors (e.g., invalid credentials).
Common causes: Incorrect client_id/client_secret or missing scopes.
Provider Buttons Missing: Verify:
SocialmentPlugin.theme.css).Login Hooks:
Use preLogin/postLogin to modify behavior:
Socialment::preLogin(function (ConnectedAccount $account) {
if ($account->provider === 'github' && !$account->user->isActive()) {
throw new AbortedLoginException('Account suspended.');
}
});
Custom Views: Publish and override views:
php artisan vendor:publish --tag="socialment-views"
Modify resources/views/vendor/socialment/providers-list.blade.php for custom styling.
Provider-Specific Logic:
Extend ConnectedAccount model or create provider-specific services to handle unique attributes (e.g., Azure AD groups).
SANCTUM_STATEFUL_DOMAINS includes both frontend and backend URLs.php artisan config:clear after updating .env for Socialite credentials.How can I help you explore Laravel packages today?