πŸ” Google OAuth Setup Guide (Laravel / Socialite)

🎯 Goal

Make Google login work using only .env:

GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET=
GOOGLE_REDIRECT_URI=

πŸš€ 1. Create OAuth Credentials

Go to Google Cloud Console

Steps:

  1. Create/select a project
  2. Go to: APIs & Services β†’ OAuth consent screen

βš™οΈ Configure Consent Screen

  • Choose: External
  • Fill required:
    • App name
    • Support email
    • Developer email

Add scopes:

  • email
  • profile

βž• Add Test Users (IMPORTANT)

Scroll down β†’ Test Users

Click:

+ ADD USERS

Add:

[email protected]
[email protected]

πŸ‘‰ Only these users can log in while testing


πŸ”‘ 2. Create OAuth Client ID

Go to:
πŸ‘‰ APIs & Services β†’ Credentials

Click:

+ CREATE CREDENTIALS β†’ OAuth Client ID

Select:

  • Web Application

Add Redirect URI:

http://sprintly.test/auth/google/callback

⚠️ Must match Laravel exactly


πŸ“¦ 3. Put Credentials in .env

GOOGLE_CLIENT_ID=xxxx.apps.googleusercontent.com
GOOGLE_CLIENT_SECRET=xxxx
GOOGLE_REDIRECT_URI=http://yoursite.com/auth/google/callback

πŸ”„ 4. Apply Changes

php artisan config:clear
php artisan cache:clear

πŸ§ͺ Testing vs Production

πŸ§ͺ Testing Mode (Default)

  • Only Test Users can log in
  • No verification needed

πŸ‘‰ Use for:

  • development
  • demo
  • client testing

🌍 Publish App (Production)

  • Anyone can log in
  • May require Google verification

πŸ‘‰ Use when:

  • app is fully live
  • real users need access

🧠 Decision Rule

  • Few users β†’ Stay in Testing
  • Public system β†’ Publish later

⚠️ Common Errors

❌ redirect_uri_mismatch

β†’ .env and Google Console don’t match exactly


❌ invalid_client

β†’ wrong client ID / secret


❌ This app isn’t verified

β†’ user not in Test Users OR app not published


⚑ Local vs Production

Local:

GOOGLE_REDIRECT_URI=http://sprintly.test/auth/google/callback

Production:

GOOGLE_REDIRECT_URI=https://yourdomain.com/auth/google/callback

πŸ‘‰ Add BOTH in Google Console


🧠 Final Mental Model

  • Consent Screen β†’ user-facing setup
  • Client ID β†’ app credentials
  • Test Users β†’ who can log in (testing mode)
  • Publish App β†’ open to public

βœ… TL;DR

  • Setup consent screen
  • Add test users
  • Create OAuth Client ID
  • Paste in .env
  • Match redirect exactly