,

How to generate GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET

Posted by

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

  1. Go to “APIs & Services” → “Library”
  2. Search and enable:
    • Google+ API (sometimes not needed)
    • Google Identity Services / OAuth 2.0 Client

🔑 Step 4: Create OAuth 2.0 Credentials

  1. Go to APIs & Services → Credentials
  2. Click Create Credentials → OAuth Client ID
  3. 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

  1. Choose “Web application”
  2. Set name: MyHospitalNow OAuth
  3. Under Authorized redirect URIs, add: https://www.abd.com/nurses/auth/google/callback
  4. Click Create

✅ You will get:

  • Client ID → Paste into .env as GOOGLE_CLIENT_ID
  • Client Secret → Paste into .env as GOOGLE_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

Your email address will not be published. Required fields are marked *

0
Would love your thoughts, please comment.x
()
x