overtrue/laravel-socialite
Laravel Socialite for Chinese social platforms: OAuth login drivers for WeChat, Weibo, QQ, Douyin and more. It keeps the familiar Socialite API, uses config-driven credentials, and handles redirects and callbacks cleanly, so you can add these providers with the same flow you use for GitHub or Google...
composer require overtrue/laravel-socialite. If you're still on Laravel 10, pin to ^4.0.1 — 4.1.0 is the Laravel 11 line, so treat the upgrade as tied to your framework upgrade, not as an independent package bump.Overtrue\LaravelSocialite\SocialiteServiceProvider and the Socialite facade alias are registered automatically. No manual config/app.php edits needed on Laravel 11.php artisan vendor:publish --provider="Overtrue\LaravelSocialite\SocialiteServiceProvider" to get config/socialite.php. Put credentials in .env (*_CLIENT_ID, *_CLIENT_SECRET, *_REDIRECT_URI) and reference them from the config file — never inline secrets.config/socialite.php for driver setup, then the package's manager/facade surface (Socialite::driver('github')). Check composer.json of the package for the exact illuminate/* and overtrue/socialite constraints, since the driver list and minimum PHP version come from the underlying library, not this wrapper.Socialite::driver($provider)->redirect() and one that receives the callback and calls ->user(). That's the whole loop; everything else is mapping that user onto your own users table.Route::get('/auth/{provider}/redirect', [OAuthController::class, 'redirect']);
Route::get('/auth/{provider}/callback', [OAuthController::class, 'callback']);
Keep the callback route behind the web middleware group — the state/session check depends on it.(provider, provider_id) first, fall back to email match only if you're confident the provider verifies emails, and only then create. Store the provider id in a social_accounts table if a user can link multiple providers.
$social = Socialite::driver($provider)->user();
$account = SocialAccount::firstOrNew(['provider' => $provider, 'provider_id' => $social->getId()]);
Socialite::driver($provider)->stateless() when the flow starts from a mobile app or a token-based SPA. You lose CSRF protection on the callback, so add your own signed state parameter and validate it.->scopes([...]) and ->with(['prompt' => 'consent']) on the redirect call. Read them from config rather than hardcoding, so you can request extra scopes (e.g. refresh tokens) per environment.config('socialite.providers') array plus {provider} route parameter lets you add a new provider without touching the controller. Validate the provider name against the config keys before passing it to driver().Socialite::shouldReceive('driver->user')->andReturn($fakeUser)) and assert the redirect and callback behaviour, user creation, and duplicate-account handling separately.app/Http/Kernel.php. If your callback needs session or cookie middleware, register it in bootstrap/app.php (->withMiddleware(...)), and register any custom listeners/providers in bootstrap/providers.php. Older tutorials referencing Kernel.php will mislead you.TrustProxies) or the generated URL will be http:// and the provider will reject it.config/socialite.php or .env on a deployed environment, run php artisan config:clear / config:cache. Stale cached config is the usual cause of "it works locally".InvalidStateException: almost always a missing session, a cookie domain mismatch, or a user who took too long. Don't retry silently — redirect back to the login page with a flash message.overtrue/socialite; providers outside its built-in list need an additional driver package. Check available drivers before promising a provider to a stakeholder.->user() in a try/catch for InvalidStateException and HTTP/request exceptions. Providers return error=access_denied on the callback when users cancel — treat that as a normal path, not a 500.Socialite:: throughout the app. That keeps the package boundary in one place and makes a future swap or upgrade cheap.How can I help you explore Laravel packages today?