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
- Open Google Cloud Console
- Click Select Project → New Project
- Enter a Project Name
- Click Create
Step 2: Configure OAuth Consent Screen
- Navigate to APIs & Services → OAuth Consent Screen
- Select External
- Enter App Name and Email
- Save and Continue
OAuth consent screen shows the permissions your app requests from users. :contentReference[oaicite:1]{index=1}
Step 3: Create OAuth Client
- Go to APIs & Services → Credentials
- Click Create Credentials
- Select OAuth Client ID
- 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