Logo

Google OAuth Setup

⚠️ Important: The screenshots and step-by-step instructions on this page reflect the interface as of December 2025. Third-party services like Google, Facebook, and Microsoft frequently update their user interfaces. While the general process remains similar, the exact screens, button labels, and menu locations may differ from what you see. If you encounter significant differences, consult the provider's official documentation.

This guide walks you through setting up Google OAuth authentication for your site.

Quick Setup (Already Have Credentials?)

If you already have a Google OAuth Client ID and Secret, just add them to appsettings.json:

{
  "Authentication": {
    "EnableGoogleAuth": true,
    "Google": {
      "ClientId": "your-client-id.apps.googleusercontent.com",
      "ClientSecret": "your-client-secret"
    }
  }
}

Ensure your redirect URI is configured: https://yourdomain.com/signin-google

Prerequisites

Step 1: Create a Google Cloud Project

  1. Go to the Google Cloud Console
  2. Click the project dropdown at the top of the page
  3. Click New Project
  4. Enter a project name (e.g., "My Web App")
  5. Click Create
  6. Wait for the project to be created, then select it

Step 2: Configure OAuth Consent Screen

  1. In the left sidebar, navigate to APIs & ServicesOAuth consent screen
  2. Select External user type (unless you have a Google Workspace organization)
  3. Click Create
  4. Fill in the required fields:
    • App name: Your application name
    • User support email: Your email address
    • Developer contact email: Your email address
  5. Click Save and Continue
  6. On the Scopes page, click Add or Remove Scopes
  7. Select the following scopes:
    • email
    • profile
    • openid
  8. Click Update, then Save and Continue
  9. Add test users if in testing mode, then click Save and Continue

Step 3: Create OAuth Credentials

  1. In the left sidebar, go to APIs & ServicesCredentials
  2. Click + Create CredentialsOAuth client ID
  3. Select Web application as the application type
  4. Enter a name (e.g., "Web Client")
  5. Under Authorized redirect URIs, add:
    • For development: https://localhost:{port}/signin-google
    • For production: https://yourdomain.com/signin-google
  6. Click Create
  7. Copy the Client ID and Client Secret
Important: Keep your Client Secret secure! Never commit it to source control or expose it in client-side code.

Step 4: Configure Your Application

Add the credentials to your appsettings.json:

{
  "Authentication": {
    "EnableGoogleAuth": true,
    "Google": {
      "ClientId": "your-client-id.apps.googleusercontent.com",
      "ClientSecret": "your-client-secret"
    }
  }
}
For Development: Use User Secrets instead of appsettings.json:
dotnet user-secrets set "Authentication:Google:ClientId" "your-client-id"
dotnet user-secrets set "Authentication:Google:ClientSecret" "your-client-secret"

Redirect URI Format

Environment Redirect URI
Development https://localhost:5001/signin-google
Production https://yourdomain.com/signin-google

Troubleshooting

Error: redirect_uri_mismatch
The redirect URI in your request doesn't match any authorized URIs. Check that the URI in Google Cloud Console exactly matches your application's callback URL, including the port number and protocol (https).
Error: access_denied
The user denied the permission request, or the app is in testing mode and the user isn't added as a test user.
Error: invalid_client
Check that your Client ID and Client Secret are correct and properly configured.