Laravel 8 — Integrate Jetstream + Socialite in 30 mins

andyyou
2 min readOct 23, 2020

--

This post is an updated version from Laravel 7 — Socialite in Action ( Social Media Login Integration with Facebook, Twitter, LinkedIn, Google), but reduce explain to help those experienced users migrate to Laravel 8 as soon as possible.

Create Project

After create the project please create a database and setup .env for it. I am using postgresql so for for example I will...

DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
DB_PORT=5432
DB_DATABASE=demo
DB_USERNAME=root
DB_PASSWORD=

Install Jetstream

Install Socialite

Modify database schema

You can reference to the last post to understand why this step exists. — Laravel 7 — Socialite in Action ( Social Media Login Integration with Facebook, Twitter, LinkedIn, Google)

In the new migration file:

Then

Model

Fortify

There are two relevant files need to update validation rule because we now support SoftDeletes. NOTE email rule update unique part with unique:users,email,NULL,id,deleted_at,NULL.

Get key and secret from the platform

Please reference the last post

FACEBOOK_CLIENT_ID=
FACEBOOK_CLIENT_SECRET=
FACEBOOK_CALLBACK_URL=/login/facebook/callback
GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET=
GOOGLE_CALLBACK_URL=/login/google/callback
LINKEDIN_CLIENT_ID=
LINKEDIN_CLIENT_SECRET=
LINKEDIN_CALLBACK_URL=/login/linkedin/callback
TWITTER_CLIENT_ID=
TWITTER_CLIENT_SECRET=
TWITTER_CALLBACK_URL=/login/twitter/callback

Services configuration

In config/services.php we should register our services. You may notice we add scopes but they don't reveal on an official document. Yes it is additationl config option I think it better put them together, you can also put it into .env but need more process to deal with.

Controller

It’s most important and you are looking for. Here we will create a controller by ourself to handle the OAuth callback

After creating the file I will show you entire app/Http/Controllers/Auth/LoginController.php which is easy to copy and help you figure out everything.

Routes

In routes/web.php,NOTE that Laravel 8 uses new syntax for define routes.

Views

Finally, under resources/views/auth/, place button you want.

Update: 2020–10–28

Please note, because of password now is not required for those sign in with socialite so fortify ‘s features should change:

Features::twoFactorAuthentication([  'confirmPassword' => false,]),

--

--

Responses (1)