To generate the values for:
GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET=
GOOGLE_URL=
you must register your app with Google and set up OAuth 2.0 credentials. Here’s a complete guide:
✅ Step-by-Step: Generate Google OAuth Credentials
🔐 Step 1: Go to Google Cloud Console
🔗 Link: https://console.cloud.google.com/apis/credentials
🏗️ Step 2: Create / Select a Project
- Click on the top dropdown and either:
- Select an existing project, or
- Click New Project → Give a name (e.g.,
MyHospitalNow
) → Click Create
🔌 Step 3: Enable APIs
- Go to “APIs & Services” → “Library”
- Search and enable:
- ✅ Google+ API (sometimes not needed)
- ✅ Google Identity Services / OAuth 2.0 Client
🔑 Step 4: Create OAuth 2.0 Credentials
- Go to APIs & Services → Credentials
- Click Create Credentials → OAuth Client ID
- If it asks to configure OAuth consent screen:
- Choose “External”
- Fill app info: App name, support email, and add scopes like
openid
,email
,profile
- Add test users (email IDs of people who will test this first)
- Save and continue
🛠️ Step 5: Configure OAuth Client
- Choose “Web application”
- Set name:
MyHospitalNow OAuth
- Under Authorized redirect URIs, add:
https://www.abd.com/nurses/auth/google/callback
- Click Create
✅ You will get:
- Client ID → Paste into
.env
asGOOGLE_CLIENT_ID
- Client Secret → Paste into
.env
asGOOGLE_CLIENT_SECRET
✅ Example .env
GOOGLE_CLIENT_ID=Your Client ID
GOOGLE_CLIENT_SECRET=Your Secret
GOOGLE_URL=https://www.abd.com/nurses/auth/google/callback
⚙️ Laravel Configuration
In config/services.php
:
'google' => [
'client_id' => env('GOOGLE_CLIENT_ID'),
'client_secret' => env('GOOGLE_CLIENT_SECRET'),
'redirect' => env('GOOGLE_URL'),
],
In routes:
Route::get('auth/google', [LoginController::class, 'redirectToGoogle']);
Route::get('auth/google/callback', [LoginController::class, 'handleGoogleCallback']);
In controller:
use Socialite;
public function redirectToGoogle() {
return Socialite::driver('google')->redirect();
}
public function handleGoogleCallback() {
$user = Socialite::driver('google')->stateless()->user();
// $user->getEmail(), $user->getName(), etc
}
📦 Required Package
Install Socialite:
composer require laravel/socialite
Let me know if you want full working code or a GitHub repo for Google Login via Laravel.
Leave a Reply