Google Client API - Missing require parameter: redirect_uri

Google Client API - Missing require parameter: redirect_uri

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

Google Client API - Missing require parameter: redirect_uri

Encountering an Error 400 (OAuth 2 Error) stating that a required parameter redirect_uri is missing usually points to a fundamental mismatch between your application's configuration and the OAuth consent screen setup in the Google Cloud Console. This specific error often surfaces when attempting to authenticate via a web browser, yet the Google_Client object fails to find a registered callback address associated with the request.

The root cause frequently lies in how the Authorization URL is constructed versus what is registered as an authorized redirect URI. In the provided code snippet, the application attempts to handle authentication within a PHP class structure. The critical line responsible for generating the authorization URL is $this->googleClient->createAuthUrl(). For this method to work correctly in a web context, the client instance must be aware of where Google should send the user after they grant consent.

To resolve this, you must explicitly set the redirect URI before calling createAuthUrl(). The code provided relies on default behavior or attempts to read it from a config file, but if that isn't populated correctly for your specific environment, the generated URL will lack the redirect_uri query parameter. Google's server then rejects the request because it cannot validate the callback address against your project's whitelist.

Configuring Redirect URIs in the Cloud Console

A common point of confusion arises when developers attempt to register http://localhost/ or similar local addresses in the Google Cloud Console under "OAuth consent screen" > "Authorized redirect URIs." The error message you received—"Sorry, there's a problem... check it and try again"—typically indicates that the domain is not being recognized as a valid web address for OAuth purposes.

Google's API documentation enforces strict requirements for these URLs. You cannot simply use localhost or 127.0.0.1. Instead, you must use a loopback IP address with a specific port and protocol combination that matches your server configuration exactly. For example:

  • http://127.0.0.1:8000/auth/google/callback
  • http://[::1]:8000/auth/google/callback

The path component after the domain (e.g., /auth/google/callback) must also match exactly what your application expects to handle the callback request. If your code is designed to intercept the response at a specific route, that full URL must be registered in the console. Mismatches here result in the "Invalid Request" errors described in your source material.

Implementing the Fix in PHP

To fix the missing parameter issue without relying on potentially incorrect defaults, you should explicitly define the redirect URI in your PHP class constructor or initialization method. This ensures that createAuthUrl() generates a valid URL containing the necessary query parameters.

Here is how you can modify the client setup to enforce the correct redirect URI:

// Inside your scheduler::__construct() method
$this->googleClient = new Google_Client();

// Set the application name and scopes
$this->googleClient->setApplicationName(APPLICATION_NAME);
$this->googleClient->setScopes(SCOPES);
$this->googleClient->setAccessType("offline");

// Explicitly define the redirect URI
// Replace this with your actual local development URL (e.g., http://127.0.0.1:8000/callback)
$redirectUri = "http://127.0.0.1:8000/oauth2callback"; 
$this->googleClient->setRedirectUri($redirectUri);

// Add your developer key or load auth config as needed
$this->googleClient->setDeveloperKey("AIzaSyBmJLvNdMYuFhVpWalkUdyStrEBoVEayYM");

By calling setRedirectUri() before generating the authorization link, you guarantee that the resulting URL includes the required parameter. When the user visits this URL and grants permission, Google will redirect them back to your server at the exact path defined in $redirectUri. Your application must then have a route configured to catch this specific URI, extract the access_token from the query string, and exchange it for an ID token or refresh token if necessary.

Handling Credentials and Refresh Tokens

Your original code also attempts to manage credentials via files (credentials.json). While this approach works well for CLI tools, web applications often require a different lifecycle management strategy. Storing raw access tokens in plain text files can be risky due to their short expiration windows. The recommended pattern involves storing the refresh token securely and using refreshToken() when the current access token expires, rather than overwriting the entire file contents with just the access token.

Additionally, ensure that the CLIENT_SECRET_PATH points to a valid JSON file downloaded from the Google Cloud Console API & Services credentials section. If this file is missing or malformed, the client initialization might fail silently or behave unpredictably when constructing URLs.

Finally, remember that for production environments, you cannot use localhost addresses. You must register your live domain (e.g., https://example.com) in the authorized redirect URIs before deploying the application to handle user authentication securely.

Our network