Blog
Laravel Socialite: Adding Google and Other OAuth Logins
Laravel Socialite adds Google and other OAuth logins to a session app. Laravel Breeze is the older scaffolding this page pairs with that callback.
Muhammad Zubair Akhtar
Laravel Socialite is Laravel's first-party package for an OAuth login. The browser leaves your app, Google or another provider asks for permission, and the callback returns to a route you own. Socialite reads that callback and gives you a user object. Auth::login then starts the same session a password form would start. Laravel Breeze is one way that password form, the register screen, and the logout route already exist. The Laravel 13 starter kits are the other way. Socialite sits beside either of them. It does not replace the session screens, and it does not mint an API token.
I am Zubair Akhtar, a senior software engineer in Lahore, Pakistan. I ship Laravel applications where a person signs in and then stays signed in. The screen that person sees after login, Livewire or Inertia, is a separate choice, covered in Laravel Livewire vs Inertia. A staff panel on top of the same user is Laravel Filament. A JSON API that a mobile client calls with a token is Laravel REST API best practices. If you want the provider app, the callback, and the session row fitted to an app you already run, that work is Laravel development.
On 23 November 2026 I read the Laravel 13.x Socialite documentation, the 13.x starter kits documentation, and the 11.x starter kits documentation, which still carries the Breeze page and a banner that it is an old version. The same day I read the Packagist metadata for laravel/socialite, laravel/breeze, and laravel/framework. I read the v5.33.0 GitHub release, SocialiteManager.php, GoogleProvider.php, and AbstractProvider.php at that tag, the Breeze v2.4.2 release, the Breeze README and InstallCommand.php at that tag, the Blade routes/auth.php stub, and the users migration on the laravel/laravel 13.x branch. I have not installed Socialite or Breeze for this article. I have not run these snippets.
Figure 1. Four steps. The provider sees the consent screen. Laravel sees a guest on the way out and a session on the way back.
What Laravel Socialite is
The Socialite introduction says that, in addition to typical form-based authentication, Laravel provides a way to authenticate with OAuth providers using Laravel Socialite. The routing section says you need two routes. One redirects the user to the provider. The other receives the callback after the person approves the request.
The documented pair, for GitHub, is:
use Laravel\Socialite\Socialite;
Route::get('/auth/redirect', function () {
return Socialite::driver('github')->redirect();
});
Route::get('/auth/callback', function () {
$user = Socialite::driver('github')->user();
// $user->token
});
redirect sends the browser to the provider. user reads the incoming request and retrieves the profile after approval. That is the whole hop. The package does not create the users table, it does not render /login, and it does not decide what "logged in" means after the profile arrives. The storage section is the next step, and it is ordinary Laravel: find or create a User, then Auth::login($user).
The import on that page is Laravel\Socialite\Socialite. The Packagist extra for v5.33.0 also registers the service provider Laravel\Socialite\SocialiteServiceProvider and the alias Socialite to Laravel\Socialite\Facades\Socialite. The snippets below follow the import the documentation page prints.
Socialite is the wrong tool when the client is not a browser walking through a consent screen. A stateless call that already holds a token is a later section on this page, and it is a short one. A JSON API that issues its own tokens is the REST API page. I am keeping those apart on purpose.
Versions this was written against
Packagist listed laravel/socialite v5.33.0 with a version time of 11 November 2026, 14:30 UTC. The GitHub release v5.33.0 was published later, on 17 November 2026, 15:22 UTC. The release notes say the change is "Treat a non-string state as invalid", pull request 801. The license on that Packagist version is MIT.
The require list I read for v5.33.0 is PHP ^8.2, ext-json, firebase/php-jwt ^6.4|^7.0, guzzlehttp/guzzle ^7.15.2|^8.0.1, league/oauth1-client ^1.11, phpseclib/phpseclib ^4.0, and illuminate/contracts, illuminate/http, and illuminate/support at ^12.0|^13.0. An application still on Laravel 11 does not satisfy that Illuminate constraint. Packagist still listed v5.31.0, time 31 August 2026, with PHP ^8.1 and those same Illuminate packages at ^6.0|^7.0|^8.0|^9.0|^10.0|^11.0|^12.0|^13.0. I am writing against 5.33.0. I am not telling a Laravel 11 app to pretend it matches the 5.33.0 line.
laravel/framework v13.43.0 had a version time of 17 November 2026, 14:58 UTC, and requires PHP ^8.3. Socialite's own PHP floor on 5.33.0 is 8.2. An app on framework 13.43.0 follows the higher floor.
The upgrade guide committed in the v5.33.0 tag already contains a section titled "Upgrading To 6.0 From 5.x". That section says PHP 8.1 is the minimum and that phpseclib 4.0 is required. Packagist, when I read it on 23 November 2026, did not list a 6.0 release. The published 5.33.0 constraints are already PHP ^8.2 and phpseclib ^4.0. I am not going to treat the 6.0 heading in that file as a version you can require today.
Packagist listed laravel/breeze v2.4.2 with a version time of 14 May 2026, 16:54 UTC. The GitHub release v2.4.2 was published on 19 May 2026, 18:41 UTC, and its note is "Fix: Remove bootstrap.js import for Laravel 13+". The require list on that Packagist version is PHP ^8.2.0, illuminate/console, illuminate/filesystem, illuminate/support, and illuminate/validation at ^11.0|^12.0|^13.0, and symfony/console ^7.0|^8.0. The description is "Minimal Laravel authentication scaffolding with Blade and Tailwind." The README at the v2.4.2 tag says this starter kit is for Laravel 11.x and prior, and it points at the current starter kits. Both sentences are in the files I read. The constraint allows Laravel 13. The README says who the kit is for.
Providers the 13.x page names
The Socialite introduction says Socialite currently supports authentication via Facebook, X, LinkedIn, Google, GitHub, GitLab, Bitbucket, and Slack. Adapters for other platforms are on the community Socialite Providers site. I opened that site on 23 November 2026. I am not going to copy its catalog into this page.
The configuration section says the credentials go in config/services.php under one of these keys: facebook, x, linkedin-openid, google, github, gitlab, bitbucket, slack, or slack-openid.
| Driver key in the docs | What I read beside that name |
|---|---|
google | The optional-parameters example. GoogleProvider at v5.33.0 |
github | The routing and storage examples |
facebook | userFromToken can take a nonce for Facebook Limited Login |
x | Named in the introduction and as a config key |
linkedin-openid | The config key the configuration section prints |
gitlab | Config key. createGitlabDriver also passes host |
bitbucket | Named in the introduction and as a config key |
slack / slack-openid | User token by default. asBotUser() switches the slack driver |
SocialiteManager.php at the v5.33.0 tag also has createTwitchDriver and createTwitterDriver. The introduction I read does not list Twitch or Twitter. The Twitter factory uses Laravel\Socialite\One\TwitterProvider unless services.twitter has oauth set to 2, in which case it builds the OAuth 2 provider. X is a separate method, createXDriver, in the OAuth 2 namespace. I am treating the documentation list as the supported set. The extra methods are why I will not tell you the introduction sentence is the full class list, and I am not writing a Twitch setup from a method name.
GitLab is the one host detail I will mention. createGitlabDriver calls setHost with $config['host'] ?? null. A GitLab config that includes host is what that line reads. I have not read the body of setHost.
Slack bot tokens
Slack is the provider the Socialite page spends a subsection on. It says Slack has bot tokens prefixed with xoxb- and user tokens prefixed with xoxp-. The slack driver generates a user token by default, and user() returns the person's details.
Bot tokens are for an application that sends notifications to a Slack workspace the user owns. The documented redirect is:
return Socialite::driver('slack')
->asBotUser()
->setScopes(['chat:write', 'chat:write.public', 'chat:write.customize'])
->redirect();
The callback has to call asBotUser() again before user(). The page says the object is still a Laravel\Socialite\Two\User, and that only the token property is hydrated. That token is what you store if the point of the hop was a bot token rather than a login. A login for a person uses the default user token and then Auth::login. I would not mix those two outcomes in one callback.
Install Socialite and configure the provider
The installation section is one Composer line:
composer require laravel/socialite
The configuration section says you create a developer application in the provider's dashboard and put the credentials in config/services.php. This is the GitHub block that page prints:
'github' => [
'client_id' => env('GITHUB_CLIENT_ID'),
'client_secret' => env('GITHUB_CLIENT_SECRET'),
'redirect' => 'http://example.com/callback-url',
],
The same page says that if redirect is a relative path, it is resolved to a fully qualified URL. In SocialiteManager.php at v5.33.0, formatRedirectUrl leaves an absolute redirect alone. A value that starts with / is joined to config('app.url'). If that root is not an absolute http or https URL, the method throws InvalidArgumentException with the message "An absolute HTTP(S) app.url is required for relative Socialite redirect URLs."
That is the production constraint I care about. APP_URL has to be the public origin, with the scheme, before a relative callback will resolve. The host that terminates TLS for that origin is the nginx setup guide. The place that origin is set on a VPS deploy is deploy Laravel to a VPS. Inside Compose, the same variable has to be the public URL, not the container name, which is the sort of environment split covered in the Laravel Docker setup.
buildProvider in that manager requires client_id, client_secret, and redirect. If any of those keys is missing it throws DriverMissingConfigurationException. I did not read the exception's message text. The missing-key check is the part I read.
A Google block in the same shape, with a relative callback, is the configuration I would write. The keys are the ones the docs use. The path is mine, and I have not registered it with Google:
'google' => [
'client_id' => env('GOOGLE_CLIENT_ID'),
'client_secret' => env('GOOGLE_CLIENT_SECRET'),
'redirect' => '/auth/google/callback',
],
The value in the provider's dashboard has to be the URL Socialite will send, which is APP_URL plus /auth/google/callback when the config value is relative. A mismatch is the provider's error, not a Laravel exception. I have not clicked through a Google Cloud console for this article, so I am not going to invent the screen names.
Redirect, callback, and Auth::login
The storage section on the Socialite page is the piece that turns a profile into a session. This is the callback that page prints:
use App\Models\User;
use Illuminate\Support\Facades\Auth;
use Laravel\Socialite\Socialite;
Route::get('/auth/callback', function () {
$githubUser = Socialite::driver('github')->user();
$user = User::updateOrCreate([
'github_id' => $githubUser->id,
], [
'name' => $githubUser->name,
'email' => $githubUser->email,
'github_token' => $githubUser->token,
'github_refresh_token' => $githubUser->refreshToken,
]);
Auth::login($user);
return redirect('/dashboard');
});
The lookup key is github_id, the provider's id, not the email. The attributes written on update are the name, the email, and the two tokens. Then Auth::login starts the session, and the response redirects to /dashboard.
The same shape for Google is the documented callback with the driver and the column names changed from github to google. The properties id, name, email, token, and refreshToken are the ones the user-details section lists for an OAuth 2.0 provider. I have not run this:
Route::get('/auth/google/callback', function () {
$googleUser = Socialite::driver('google')->user();
$user = User::updateOrCreate([
'google_id' => $googleUser->id,
], [
'name' => $googleUser->name,
'email' => $googleUser->email,
'google_token' => $googleUser->token,
'google_refresh_token' => $googleUser->refreshToken,
]);
Auth::login($user);
return redirect('/dashboard');
});
The redirect route that matches it is the documented redirect with the same rename:
Route::get('/auth/google/redirect', function () {
return Socialite::driver('google')->redirect();
});
Columns the skeleton does not have
On 23 November 2026 I read database/migrations/0001_01_01_000000_create_users_table.php on the 13.x branch of laravel/laravel, commit a255d7688770af9713daff1439c47ff9bc6abd47, committed 13 November 2026. The users table in that file is id, a required name, a required unique email, a nullable email_verified_at, a required password string, rememberToken(), and timestamps. The same migration creates password_reset_tokens and sessions.
That file has no github_id, no google_id, and no token columns. The documented updateOrCreate writes github_id. The table has to gain that column before the example matches the schema. I am not going to invent a varchar length for an OAuth token. The Socialite page does not publish a migration. Adding the column is part of using the example, and I have not written one for this article.
password in that migration is $table->string('password') with no nullable(). The documented updateOrCreate does not set password. An insert of a brand-new row against that column needs a password value, or the column has to change. The Socialite page does not choose which. I have not executed the insert.
email is unique and not nullable in that migration. The documented lookup is the provider id, so two providers do not share a column. They can still collide: a second row with the same email fails the unique index. A person who already registered with the password form and then uses Google with the same address is that collision. I would look the email up before inserting, and I would decide in the application whether to attach google_id to the existing row. That decision is not in the snippet. I have not built it.
GoogleProvider::mapUserToObject at v5.33.0 sets id from the sub claim. The comment above a few copied fields still says they were kept for 4.0 compatibility and would be removed in 5.0. The copies are still in the 5.33.0 file. The id you store is the mapped id, which that method fills from sub.
A charge after this user exists is a different integration. The card form, the webhook, and the local payment row are Stripe payment integration in Laravel. Socialite does not see that payment.
Where Laravel Breeze fits
Laravel Breeze, on the 11.x starter kits page, is a minimal implementation of Laravel's authentication features: login, registration, password reset, email verification, and password confirmation, plus a profile page for the name, the email, and the password. The default views are Blade and Tailwind. The page also offers Livewire, and Inertia with Vue or React. It tells you the page is for an old Laravel version and to consider Laravel 13.
The install on that page is composer require laravel/breeze --dev, then:
php artisan breeze:install
php artisan migrate
npm install
npm run dev
The page says breeze:install prompts for the frontend stack and the testing framework, and that Breeze publishes its code into the application. The Blade and Inertia sections say the routes live in routes/auth.php, and that /login and /register are the URLs you open.
The command signature in InstallCommand.php at v2.4.2 is breeze:install {stack} with stacks blade, livewire, livewire-functional, react, vue, and api. The options on that signature are --dark, --pest, --ssr, --typescript, --eslint, and --composer. The 11.x page describes the prompt. The signature is the list of stack names in the tag I read. livewire-functional is on the signature. I did not see that name in the 11.x sections I read.
I read the Blade stub stubs/default/routes/auth.php at v2.4.2. The guest middleware group contains register, login, forgot-password, and reset-password. The auth middleware group contains email verification, password confirmation, the password update, and logout. There is no Socialite route in that file. Breeze does not ship the OAuth hop. You add it.
The callback runs before Auth::login, so the person hitting it is still a guest. The stub's auth group is for someone who already has a session. I would register the redirect and the callback where a guest can reach them, next to the guest routes, rather than inside the auth group. I have not installed the stack, so this is a reading of that stub plus the documented callback, not a request I sent.
The 11.x page also has a "Breeze and Next.js / API" section. It says that stack adds FRONTEND_URL and that APP_URL should be the URL serve uses. This page does not follow that section. A browser session is the login I am describing. A JSON API for a client that is not that session is Laravel REST API best practices.
The Livewire stack and the Inertia React or Vue stacks are the same session with a different UI. Which of those UIs fits the product is Laravel Livewire vs Inertia. Breeze's job, when the app already has it, is the session scaffolding Socialite's Auth::login lands in.
Laravel 13 starter kits and WorkOS
The 13.x starter kits page does not mention Breeze. I searched the page I read. The kits it documents are React, Svelte, Vue, and Livewire. It says the starter kits use Laravel Fortify for authentication, and that Fortify registers routes from config/fortify.php. The table on that page includes GET /login, POST /login, POST /logout, GET /register, and POST /register, plus password reset, email verification, password confirmation, and a two-factor challenge. You create the app with laravel new, which prompts for a kit, then npm install && npm run build and composer run dev.
Socialite is not in that route table. On a new Laravel 13 app I would keep the kit's /login and add the two Socialite routes beside it. Auth::login in the callback is the same call the Socialite page already shows. The kit owns the password form. Socialite owns the provider hop.
The same page offers a WorkOS AuthKit variant of each kit. It says that variant offers social authentication for Google, Microsoft, GitHub, and Apple, plus passkeys, email "Magic Auth", and SSO. You select WorkOS when you run laravel new. The env vars it prints are WORKOS_CLIENT_ID, WORKOS_API_KEY, and WORKOS_REDIRECT_URL set to "${APP_URL}/authenticate". It also says to set the application homepage URL in the WorkOS dashboard, which is where users land after logout. It recommends turning off "Email + Password" inside AuthKit when you want social login, passkeys, Magic Auth, and SSO only. It recommends matching the AuthKit session inactivity timeout to the Laravel session timeout, which the page says is typically two hours.
That variant is a different product choice. The provider accounts live in WorkOS. You do not composer require laravel/socialite for it, and you do not write the redirect and callback on this page. I would pick it when the kit's WorkOS option is the login you actually want. I would pick Socialite when the OAuth redirect should be code in the Laravel app, with the tokens stored on your users row.
Figure 2. Three places the session screens come from. Only the first two are where you add the Socialite routes yourself.
The person who should own that choice on a codebase, including the column for the provider id and the callback URL in production, is the hire described in the hire a Laravel developer checklist.
Scopes and the Google user
Before redirect, the Socialite page lets you add scopes. scopes merges with scopes already set. setScopes replaces them. The documented GitHub call is:
return Socialite::driver('github')
->scopes(['read:user', 'public_repo'])
->redirect();
GoogleProvider.php at v5.33.0 sets a default $scopes of openid, profile, and email, with a space as the separator. I am reading that from the property on the class. The Socialite page does not repeat those three strings. A Google login that needs a further scope would merge it with scopes or replace the list with setScopes. I have not sent either request.
The optional-parameters section shows Google with a hosted-domain hint:
return Socialite::driver('google')
->with(['hd' => 'example.com'])
->redirect();
The page says not to pass reserved keywords such as state or response_type through with. I am not going to describe Google's own rules for hd. The source I read for that call is the Socialite example.
After the callback, the user-details section lists the fields. OAuth 2.0 providers expose token, refreshToken, and expiresIn. OAuth 1.0 providers expose token and tokenSecret. Every provider on that list has getId, getNickname, getName, getEmail, and getAvatar.
GoogleProvider also implements refreshToken. The method I read calls getRefreshTokenResponse, then returns a Token built from access_token, refresh_token, expires_in, and scope. That is a later call, for a stored refresh token. It is not what the callback's user() does. I have not called it.
If you already hold an access token, the page shows userFromToken:
$user = Socialite::driver('github')->userFromToken($token);
Facebook Limited Login is the exception printed there: an iOS app returns an OIDC token, and you pass the nonce as the second argument, userFromToken($token, $nonce).
The provider URLs inside GoogleProvider at that tag are the authorization URL https://accounts.google.com/o/oauth2/auth, the token URL https://www.googleapis.com/oauth2/v4/token, and the userinfo URL https://www.googleapis.com/oauth2/v3/userinfo. Those are the strings in the file. I did not request them while writing this page.
State, relative redirects, and missing config
redirect puts a state value in the session. On the way back, hasInvalidState in AbstractProvider.php pulls that session value and compares it to the request. The v5.33.0 change, the one the release notes name, is that a request state which is not a string is invalid. The method returns true, meaning invalid, when the session state is empty, or the request state is not a string, or hash_equals fails. The previous line cast the request input to string before hash_equals. An array no longer gets that cast. The test added beside the change expects InvalidStateException when state is an array.
That is why the optional-parameters section tells you not to pass state yourself. Socialite is already using that parameter. Overwriting it, or letting a query parser turn it into an array, fails the check that v5.33.0 made explicit. stateless() is the documented way to skip the session check, and the next section is the only place I would reach for it.
The other hard failures I read in the manager are the missing config keys and a relative redirect with an APP_URL that is not absolute HTTP or HTTPS. Both throw before the browser ever leaves your app. The provider dashboard is the third check, and it happens on Google's side: the redirect URI they have stored has to equal the URL you send.
A stateless callback is a different login
The Socialite page says stateless() disables session state verification. It shows this for a stateless API that does not use cookie-based sessions:
return Socialite::driver('google')->stateless()->user();
A Breeze login and a Fortify starter-kit login are cookie sessions. The callback on those apps wants the state check. I would leave stateless() off there. The method exists for a caller that already has the provider's response and has no session to compare. It returns the Socialite user. It does not, on the page I read, call Auth::login or issue a token of your own.
Issuing a token for a JSON client is the subject of Laravel REST API best practices. I am not repeating that design here. The split I want is small: Socialite on this page ends in a session. A client that cannot hold that session needs the API page.
Faking the provider in a test
The testing section says Socialite::fake mocks the provider so the test does not call it. Faking the redirect:
use Laravel\Socialite\Socialite;
test('user is redirected to github', function () {
Socialite::fake('github');
$response = $this->get('/auth/github/redirect');
$response->assertRedirect();
});
Faking the callback takes a Laravel\Socialite\Two\User. This is the test the page prints, including the name and the email in the example:
use Laravel\Socialite\Socialite;
use Laravel\Socialite\Two\User;
test('user can login with github', function () {
Socialite::fake('github', User::fake([
'id' => 'github-123',
'name' => 'Jason Beggs',
'email' => '[email protected]',
]));
$response = $this->get('/auth/github/callback');
$response->assertRedirect('/dashboard');
$this->assertDatabaseHas('users', [
'name' => 'Jason Beggs',
'email' => '[email protected]',
'github_id' => 'github-123',
]);
});
The page says the fake user includes token values by default, and that you can override token, refreshToken, expiresIn, and approvedScopes. OAuth 1 users use Laravel\Socialite\One\User. The route in the example is /auth/github/callback, which is not the /auth/callback path from the routing section. The test and the route have to name the same URL. I have not run either test. Breeze's --pest option is how that stack installs Pest. The test() function in these snippets is the shape the Socialite page uses. I have not checked whether a PHPUnit install accepts it unchanged.
FAQ
What is Laravel Socialite?
Laravel Socialite is the first-party OAuth client for a Laravel login. You install laravel/socialite, put the provider credentials in config/services.php, redirect with Socialite::driver(...)->redirect(), and read the profile with user(). The 13.x page then shows Auth::login so the session matches a form login. This page is written against Socialite v5.33.0 and the Laravel 13.x docs, read on 23 November 2026.
Which providers does the 13.x page list?
Facebook, X, LinkedIn, Google, GitHub, GitLab, Bitbucket, and Slack. The config keys include linkedin-openid and slack-openid alongside slack. Other platforms are left to the community Socialite Providers site. The v5.33.0 manager also contains Twitch and Twitter driver methods that the introduction does not name.
Does Laravel Breeze include Socialite?
No. The Blade routes/auth.php stub at Breeze v2.4.2 has the session routes only. The 11.x page installs Breeze with composer require laravel/breeze --dev and php artisan breeze:install. Socialite is a second package, composer require laravel/socialite, and two routes you add. The Breeze README at v2.4.2 says the kit is for Laravel 11.x and prior.
Where do Socialite routes go on a Laravel 13 starter kit?
The 13.x starter kits page uses Fortify for /login and /register. Socialite is not one of those routes. Add the redirect and the callback yourself, then Auth::login into the session the kit already uses. The WorkOS variant is the alternative that offers Google, Microsoft, GitHub, and Apple without the Socialite package.
What did v5.33.0 change about state?
The release treats a non-string state as invalid. hasInvalidState requires the request value to be a string before hash_equals. A missing session state, a non-string request state, or a mismatch raises InvalidStateException through the user() path. The docs already tell you not to pass state in with().
If you want this on an app you already ship
The choice is which session the callback joins. An app that already has Laravel Breeze keeps those routes and gains two Socialite routes a guest can hit. A new Laravel 13 app takes a current starter kit, and Socialite is the same two routes beside Fortify. WorkOS is the kit option when you want that service to hold the social login instead.
I would set APP_URL to the public HTTPS origin, register the same callback in the provider dashboard, add the provider id column the documented updateOrCreate expects, and only then send a browser through redirect. The 13.x Socialite page and the files linked above are the source for the commands on this page. I have not run them here.
If you want that callback and the session row done on an application, start with Laravel development. The checklist for who should own it is hire a Laravel developer. The API that should stay a token design, rather than this session, is Laravel REST API best practices.
