What is Laravel Socialite?
Laravel Socialite is an official package that makes it simple to implement social login via OAuth 2.0. It supports major providers such as GitHub, Google, Facebook, X (Twitter), LinkedIn, and more — turning what would otherwise be complex OAuth flows into just a few lines of code. The following providers are supported out of the box:Social login flow
Installation
Add the package via Composer:When upgrading Socialite to a new major version, be sure to review the upgrade guide.
Configuration
config/services.php
Add credentials for each provider toconfig/services.php:
If the
redirect option contains a relative path, it will automatically be resolved to a fully qualified URL..env
Manage your credentials via environment variables. Using GitHub as an example:Authentication Flow
Routing
OAuth authentication requires two routes: one to redirect the user to the provider, and one to handle the callback.Storing the user and logging in
Retrieve the user in the callback route, persist them to the database, then log them in:Retrieving User Details
The object returned byuser() exposes the following properties and methods:
Retrieve a user from an existing token
If you already have a valid access token, retrieve the user withuserFromToken():
Stateless authentication
For stateless APIs that do not use cookie-based sessions, disable session state verification withstateless():
Database Integration
Migration
Add social login columns to theusers table:
Supporting multiple providers with provider columns
A common approach for handling multiple providers is to use provider and provider_id columns:
Linking to an existing account by email
To link a social login to an existing account that shares the same email address:Scopes and Options
Adding scopes
Use thescopes() method to append additional scopes to the authentication request:
setScopes() to replace all existing scopes:
Optional parameters
Use thewith() method to include additional parameters in the redirect request:
Slack bot tokens
To generate a Slack bot token instead of a user token, useasBotUser():
Testing
Socialite provides built-in support for mocking OAuth flows in tests — no real provider requests needed.Faking the redirect
Faking the callback
Pass a user instance tofake() to mock the user data returned by the provider. Use User::fake() to generate a fake user:
fake():
Laravel\Socialite\One\User instead.
Creating a Custom Provider
When you need a provider that isn’t built in, registering a custom driver viaSocialite::extend() is the official, recommended approach. Because SocialiteManager extends Illuminate\Support\Manager, the extension mechanism works exactly like any other Laravel driver system.
For a deeper look at the Manager pattern and how
extend() works under the hood, see the Manager class guide.1. Create the provider class
ExtendLaravel\Socialite\Two\AbstractProvider and implement the four abstract methods:
2. Register the driver in a service provider
CallSocialite::extend() inside the boot() method of AppServiceProvider:
3. Add the configuration
4. Use it like any built-in provider
Once registered, the custom provider is available through the same Socialite API:Related packages
The following Socialite extension packages are maintained by the owner of this site. All of them useSocialite::extend() under the hood — adding credentials to config/services.php is all you need to get started.
LINE
LINE SDK for Laravel. Includes Socialite OAuth login and Messaging API integration.
Bluesky
AT Protocol (Bluesky) integration. Supports OAuth authentication and posting.
Discord
Discord OAuth2 login.
Threads
Meta Threads integration. Supports OAuth authentication and the Threads API.
Amazon
Login with Amazon OAuth authentication.
Mastodon
OAuth login for Mastodon instances.
WordPress
OAuth login for WordPress.com and self-hosted WordPress.