maynagashev/laravel-social-connections
Installation
composer require maynagashev/laravel-social-connections
Add the service provider to config/app.php:
Maynagashev\SocialConnections\SocialConnectionsServiceProvider::class,
Publish Assets
php artisan vendor:publish --tag=config
php artisan vendor:publish --tag=models
php artisan vendor:publish --tag=views
Configure Providers
.env (see gist).config/services.php with .env using env() helper.Run Migrations
php artisan migrate
First Use Case: OAuth Login Use the provided Blade component in your login/signup form:
@socialLoginButtons
This renders buttons for configured providers (e.g., Google, GitHub).
User Registration via Social Login
SocialConnectionsServiceProvider::boot() to modify user creation logic:
public function boot()
{
SocialConnections::extend('user', function ($user, $social) {
$user->email = $social->email; // Force email update
});
}
Admin Management of Connections
SocialConnectionsController) to list/disconnect user connections.routes/web.php:
Route::resource('social-connections', \Maynagashev\SocialConnections\Http\Controllers\SocialConnectionsController::class);
Dynamic Provider Configuration
config/social-connections.php:
'providers' => [
'google' => [
'enabled' => true,
'scopes' => ['email', 'profile'],
],
'github' => [
'enabled' => false,
],
],
Email Handling for Providers Without Email
resources/views/vendor/social-connections/email-prompt.blade.php.SocialConnections::authenticate('google', function ($user) {
Auth::login($user);
});
SocialConnection model’s boot():
protected static function boot()
{
parent::boot();
static::addGlobalScope('tenant', function (Builder $builder) {
$builder->where('tenant_id', auth()->user()->tenant_id);
});
}
Provider Credentials Mismatch
.env and config/services.php are synced. Use php artisan config:clear if changes don’t reflect.storage/logs/laravel.log for OAuth errors (e.g., invalid client ID).Email Handling Quirks
config/social-connections.php:
'linkedin' => [
'scopes' => ['r_emailaddress'],
],
use Maynagashev\SocialConnections\Facades\SocialConnections;
SocialConnections::promptForEmail($social);
Model Conflicts
social_connections and social_users. If you’ve customized these tables, merge migrations manually.--force in migrations or reset the database:
php artisan migrate:fresh
CORS Issues with OAuth Redirects
http://your-app.test/auth/google/callback) is whitelisted in the provider’s dashboard.php artisan route:list to verify the callback route exists.Enable Debug Mode
Add to config/social-connections.php:
'debug' => env('APP_DEBUG', false),
This logs provider responses to storage/logs/social-connections.log.
Test Locally with laravel-shift
Use laravel-shift to mock OAuth responses during development:
Shift::fake();
Shift::add('google', 'user', [
'id' => '123',
'email' => 'test@example.com',
]);
Custom Social Providers
Extend the SocialConnectionsManager to add unsupported providers:
SocialConnections::extend('custom', function () {
return Socialite::driver('custom')->scopes(['custom_scope']);
});
Override Views Publish and modify the package’s views:
php artisan vendor:publish --tag=views --force
Edit resources/views/vendor/social-connections/....
Webhook Handling
For providers with webhooks (e.g., GitHub), listen to events in EventServiceProvider:
protected $listen = [
'Maynagashev\SocialConnections\Events\SocialAccountUpdated' => [
'App\Listeners\UpdateUserProfile',
],
];
Rate Limiting
Throttle social logins in app/Http/Middleware/ThrottleSocialLogins.php:
public function handle($request, Closure $next)
{
return $next($request)->throttle([
'social' => 5, // 5 attempts per minute
]);
}
How can I help you explore Laravel packages today?