Skip to main content

Setting Up Google OpenID Connect in Drupal

Adding Google SSO to a Drupal site is a common request, and the openid_connect module makes it manageable, but there are a handful of configuration details that will bite you if you're not careful. The most common one is a redirect_uri_mismatch error that appears right when you think you're done. Here's a complete walkthrough, including how to diagnose and fix that error.

What You'll Need

  • The openid_connect module installed and enabled
  • A Google Cloud account with access to Google Cloud Console
  • Your site accessible over HTTPS (Google requires it for OAuth)

Step 1: Create OAuth Credentials in Google Cloud Console

  1. Go to Google Cloud Console and select or create a project.
  2. Navigate to APIs & Services → Credentials.
  3. Click Create Credentials → OAuth client ID.
  4. If prompted, configure the OAuth consent screen first: 5. Choose Internal (Google Workspace users only) or External (any Google account) 6. Fill in the app name, support email, and developer contact info 7. Add your domain to the Authorized domains list
  5. Back in Create OAuth client ID, select Web application.
  6. Give it a name (e.g. "Drupal SSO").
  7. Under Authorized redirect URIs, add your Drupal callback URL:
https://yoursite.com/openid-connect/google
  1. Click Create and copy your Client ID and Client Secret.

Step 2: Configure the Module in Drupal

  1. Go to Configuration → Web services → OpenID Connect (/admin/config/services/openid-connect).
  2. Under Clients, enable Google and click Edit.
  3. Enter your Client ID and Client Secret from the previous step.
  4. Save the client configuration.
  5. Back on the main OpenID Connect settings page, configure: 6. Automatically connect existing users — recommended if you have existing Drupal accounts tied to Google emails 7. Override registration settings — controls whether new accounts can be created on first SSO login 8. Login with Google block or button placement (optional)
  6. Save configuration.

Step 3: Test the Login Flow

Navigate to /user/login — you should see a "Log in with Google" button. Click it, go through the Google consent screen, and...

If you see a redirect_uri_mismatch error from Google, don't panic. This is the most common issue and it's easy to fix once you know what to look for.

Fixing redirect_uri_mismatch

Google is telling you that the redirect URI Drupal sent during the OAuth handshake doesn't match any URI you've registered in Cloud Console. The mismatch is usually one of these:

Find the Exact URI Drupal Is Sending

When Google throws the error, the full error page often includes the redirect URI it received. Look for a line like:

Redirect URI: https://www.yoursite.com/openid-connect/google

Copy that exact string — this is what you need to register in Google Console.

Common Mismatch Causes

www vs. non-www If Drupal's $base_url is configured as https://yoursite.com but your site redirects to https://www.yoursite.com, or vice versa, the URIs won't match. Make sure both are registered, or lock down your $base_url in settings.php:

$settings['trusted_host_patterns'] = [
  '^yoursite\.com$',
  '^www\.yoursite\.com$',
];

http vs. https Google requires HTTPS for OAuth redirect URIs. If Drupal is behind a load balancer or reverse proxy that terminates SSL, it may generate an http:// redirect URI internally. Fix this by forcing HTTPS in settings.php:

$settings['reverse_proxy'] = TRUE;
$settings['reverse_proxy_addresses'] = ['your.proxy.ip'];

Trailing slash https://yoursite.com/openid-connect/google and https://yoursite.com/openid-connect/google/ are treated as different URIs. Check for a trailing slash discrepancy.

Multiple domains If your site is accessible at more than one domain (e.g. yourdomain.com and another.yourdomain.com), Drupal will generate different redirect URIs depending on which domain the user hits. Register all of them in Google Console:

https://yourdomain.com/openid-connect/google
https://another.yourdomain.com/openid-connect/google

After Adding the Correct URI

After updating Google Console, click the Log in with Google button again. Changes to authorized redirect URIs in Google Console take effect almost immediately — no wait time needed.

Tips for Multi-Domain or Staging Setups

  • Register your staging or dev domain as a separate set of OAuth credentials (or add those URIs to a separate client). Don't use production credentials on non-production environments.
  • For local development, Google does allow http://localhost as an authorized redirect URI, but you'll need to add it explicitly.
  • If you're using Pantheon's multidev environments, each multidev URL will need its own registered redirect URI.

Wrapping Up

Once you're past the redirect URI mismatch, Google OpenID Connect in Drupal is solid and low-maintenance. The openid_connect module handles token refresh, account linking, and user field mapping — making it a clean option for internal team tools, client portals, or any Drupal site where you want to leverage Google Workspace for authentication.