Sunday, 15 March 2026

Configure Google Authentication in ASP.NET Core (.NET 8)

Configure Google Authentication in ASP.NET Core (.NET 8)

This guide explains how to register a project and enable Google login using OAuth.

Step 1: Create Google Cloud Project

  1. Open Google Cloud Console
  2. Click Select Project → New Project
  3. Enter a Project Name
  4. Click Create

Step 2: Configure OAuth Consent Screen

  1. Navigate to APIs & Services → OAuth Consent Screen
  2. Select External
  3. Enter App Name and Email
  4. Save and Continue

OAuth consent screen shows the permissions your app requests from users. :contentReference[oaicite:1]{index=1}

Step 3: Create OAuth Client

  1. Go to APIs & Services → Credentials
  2. Click Create Credentials
  3. Select OAuth Client ID
  4. Choose Web Application

Step 4: Add Redirect URI

Add the redirect URI used by ASP.NET authentication:

https://localhost:7250/signin-google
We Can add multiple url environment basis
Example: https://dev-xyz.com/signin-google 

This URI is required so Google knows where to send the authentication response. :contentReference[oaicite:2]{index=2}

Step 5: Copy Credentials

After creating the client, Google will generate:

  • Client ID
  • Client Secret

Use these values in your ASP.NET Core configuration.

Example Configuration

builder.Services.AddAuthentication()
.AddCookie()
.AddGoogle(options =>
{
    options.ClientId = "CLIENT_ID";
    options.ClientSecret = "CLIENT_SECRET";
});

Login Flow

User clicks Google Login
→ Redirect to Google
→ User signs in
→ Google redirects to /signin-google
→ ASP.NET validates token
→ Redirect to application