🔐 🌈 Add Login with Google to your Laravel app

Connor Leech
Employbl
Published in
4 min readJun 15, 2018

--

Laravel Socialite handles login with OAuth and is officially maintained by the Laravel team.

In this tutorial we’re going to add authentication via Google to a Laravel app. We’re going to use Socialite and start from scratch.

1. Create Laravel app 🔧

Create a new laravel app with a database and get everything up and running.

2. Install Socialite 👩‍👧‍👧

Install socialite using composer. Socialite is an official Laravel package documented here.

3. Configure Laravel 🖥️

Add credentials to config/services.php. Socialite supports Facebook, Twitter, LinkedIn, Google, GitHub and Bitbucket. Other providers require packages from the community, which are all listed here.

These providers follow the OAuth 2.0 spec and therefore require a client_id, client_secret and redirect url. We’ll obtain these in the next step! First, add the values to the config file because socialite will be looking for them when we ask it to.

'google' => [
'client_id' => env('GOOGLE_CLIENT_ID'),
'client_secret' => env('GOOGLE_CLIENT_SECRET'),
'redirect' => env('GOOGLE_REDIRECT')
],

Since we added a new package, make sure to add to the service providers array in config/app.php:

--

--

Connor Leech
Employbl

Girl Dad x 2. Cofounder @Employbl. Software Engineer @CommentSold.