Vũ Văn HảiFull-stack · AI-native
GuidesBlog
Discuss a project

© 2026 Vu Van Hai · Written from real deployment experience.

HomeGuidesBlogRSS
  1. Guides
  2. /Integrations
  3. /Configure Google OAuth for a new domain (Next.js and .NET API)

Configure Google OAuth for a new domain (Next.js and .NET API)

Create a new OAuth Client ID in Google Cloud Console for a new domain, declare the right JavaScript origins and redirect URIs, then update the environment variables of the Next.js frontend and the .NET API backend.

Updated: Sep 21, 20263 min read
Google OAuthGoogle CloudNext.js.NET
On this page
  • Quick reference
  • Step 1: Register the app in Google Cloud (OAuth consent screen)
  • Step 2: Create credentials to get the Client ID and Client Secret
  • Step 3: Update the Frontend environment variables
  • Step 4: Update the Backend environment variables
  • Troubleshooting

When a system moves to a new admin email and a new domain, its Google OAuth credentials have to be redone: register the app in Google Cloud Console, get a new Client ID and Client Secret, then update the environment variables of both the Frontend (Next.js) and the Backend (.NET API). This guide walks through each step.

Throughout, example.com is the Frontend domain and api.example.com is the Backend domain - replace them with your real domains. <client-id> and <client-secret> are the two values Google gives you in Step 2.

Quick reference

  1. Google Cloud: create a Web application Client ID under Credentials.
  2. Authorized JavaScript origins: the origin URLs (http://localhost:3000, https://example.com).
  3. Authorized redirect URIs: the callback paths (e.g. .../api/auth/google/callback).
  4. Copy the generated Client ID and Client Secret.
  5. Frontend: update NEXT_PUBLIC_API_URL and NEXT_PUBLIC_GOOGLE_CLIENT_ID in .env.
  6. Backend: update Google__ClientId, Google__ClientSecret, Google__RedirectUri and Frontend__BaseUrl.

Step 1: Register the app in Google Cloud (OAuth consent screen)

If you have not created a consent screen for the new email yet:

  1. Sign in to Google Cloud Console.
  2. Create a new project or pick the existing one.
  3. Go to APIs & Services -> OAuth consent screen (or click Get Started in the new UI).
  4. Choose User Type: External and continue.
  5. Fill in the details:
    • App name: your application's name.
    • User support email and Developer contact email: your email.
    • Authorized domains: the root domain (e.g. example.com).
  6. Click Save and Continue until you reach the end (Finish).

Step 2: Create credentials to get the Client ID and Client Secret

  1. Switch to Credentials (left-hand menu).
  2. Click the blue + CREATE CREDENTIALS button (or CREATE CLIENT) -> choose OAuth client ID.
  3. For Application type, choose Web application.
  4. Give the client a Name (e.g. Project Web Client).
  5. Under Authorized JavaScript origins, add:
    • http://localhost:3000
    • https://example.com
  6. Under Authorized redirect URIs, add every callback link:
    • http://localhost:3000/vi/auth/callback
    • http://localhost:3000/en/auth/callback
    • https://example.com/vi/auth/callback
    • https://example.com/en/auth/callback
    • https://api.example.com/api/auth/google/callback (handled by the Backend)
  7. Click Create. Copy the Client ID and Client Secret right away.

The Client Secret is a server-side secret: keep it on the Backend only, NEVER put it in a NEXT_PUBLIC_* variable (it would be exposed to the browser), and don't commit the .env file to Git.

Step 3: Update the Frontend environment variables

Open the .env file (or the deploy environment settings) of the Frontend (Next.js) project and change:

# Point the Backend base URL at the new domain
NEXT_PUBLIC_API_URL=https://api.example.com/api

# The Google Client ID from Step 2
NEXT_PUBLIC_GOOGLE_CLIENT_ID=<client-id>

Step 4: Update the Backend environment variables

Open the .env file (or the production config file) of the Backend (.NET API) project and edit:

# Google OAuth settings
Google__ClientId=<client-id>
Google__ClientSecret=<client-secret>
Google__RedirectUri=https://api.example.com/api/auth/google/callback

# Frontend base URL, used for CORS and the related redirect logic
Frontend__BaseUrl=https://example.com

Troubleshooting

SymptomFix
redirect_uri_mismatch errorThe URL the browser sends to the API must match exactly, 100% (including http(s) and any trailing /) one of the entries under Authorized redirect URIs in Google Cloud
Settings just saved but sign-in still failsGoogle can take 5-10 minutes before the new settings and domain are fully live on their side - wait, then retry
Backend behind a proxy (Cloudflare / Nginx / Caddy) builds an http RedirectUri and hits mismatchConfigure Forwarded Headers (X-Forwarded-Proto) correctly so the server knows the incoming scheme is https. If you use Caddy, see the Caddy reverse proxy guide
PreviousConfigure the SePay webhook and API key to accept paymentsNextCheck and refresh the OG image cache on social platforms

Related articles

  • Set up Vertex AI for the Gemini API (keyless and service account)

    Set up Google Cloud Vertex AI (now Gemini Enterprise Agent Platform) to call Gemini models: enable the API, create a service account, authenticate keyless with ADC or with a JSON key, install the google-genai SDK, and fix org policy, 429 and 404 errors.

    Integrations

    Integrations
  • Send email with the Brevo API when your VPS blocks SMTP

    Send verification emails from a VPS through the Brevo HTTP API v3 (HTTPS, port 443) instead of blocked SMTP ports: verify the sender and domain (DKIM, SPF), grab the right API key, configure .env, and fix common errors.

    Integrations

    Integrations

Written by Vu Van Hai

I'm Hai, a full-stack developer based in Ho Chi Minh City. These guides come from systems I built and run myself. Need to build or untangle something similar? Get in touch.

Discuss a projectMore guides

Spot a mistake or a command that no longer works? Let me know

On this page

  • Quick reference
  • Step 1: Register the app in Google Cloud (OAuth consent screen)
  • Step 2: Create credentials to get the Client ID and Client Secret
  • Step 3: Update the Frontend environment variables
  • Step 4: Update the Backend environment variables
  • Troubleshooting