Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Security and hardening

Google sign-in stops with 'Error 400: invalid_request'

ErrorError 400: invalid_request

Short answer

Google returns invalid_request when the request itself is not acceptable: a malformed request, a missing parameter, an unsupported method, a deprecated out-of-band redirect, or a sign-in shown in an embedded browser. If only some client IDs fail, compare their redirect URI and flow.

  • Applies to Google OAuth 2.0 (web server and installed app flows), Google Cloud Console
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Copy the full authorization URL your app opens and read its parameters: client_id, redirect_uri, response_type, scope. Compare it with a client ID that works.

    python3 -c "import sys,urllib.parse as u; print(u.parse_qs(u.urlparse(sys.argv[1]).query))" 'PASTE_AUTH_URL'
  2. 2Match what you see, then jump to its fix

    1. 1redirect_uri is urn:ietf:wg:oauth:2.0:oob (or the code is copied by hand from a page)The app still uses the out-of-band redirectFix
    2. 2The error appears only inside your own app's built-in browserThe sign-in opens inside an embedded browser or WebViewFix
    3. 3The authorization URL lacks client_id, redirect_uri, response_type or scope, or is not URL-encodedA parameter is missing, malformed or not supportedFix

What does the error look like?

  • Error 400: invalid_request

Cause 1 of 3

The app still uses the out-of-band redirect

1Check

Google deprecated the out-of-band flow for all app types. Clients created before 28 Feb 2022 were blocked from 3 Oct 2022, and every remaining client from 31 Jan 2023. That is why an old client and a new one in the same project can behave differently. The page says it applies to apps in production status.

grep -rn 'urn:ietf:wg:oauth:2.0:oob' .

2Fix

Move to a supported flow: the loopback IP flow for desktop apps, Google's sign-in SDKs for Android and iOS, or a server-side redirect URI for web apps.

# desktop app: register a Desktop client and use a loopback redirect
redirect_uri=http://127.0.0.1:PORT

3Verify

Open the authorization URL again; the consent screen should appear.

# browser: consent screen loads without Error 400

Confirmed by developers.google.com

Did this fix it?

Cause 2 of 3

The sign-in opens inside an embedded browser or WebView

1Check

Google's policy forbids sending an authorization request to an embedded user-agent under the developer's control.

grep -rn -i 'webview' .

2Fix

Open the system browser (or Custom Tabs on Android) for the authorization request and receive the result through the redirect.

# open the authorization URL in the system browser instead of a WebView

3Verify

Sign in from the system browser; the error no longer shows.

# manual sign-in test

Confirmed by developers.google.com

Did this fix it?

Cause 3 of 3

A parameter is missing, malformed or not supported

1Check

Google lists invalid_request as: improperly formatted request, missing required parameters, or an unsupported authorization method. Print the parameters (first step) and compare with a working client.

python3 -c "import sys,urllib.parse as u; print(u.parse_qs(u.urlparse(sys.argv[1]).query))" 'PASTE_AUTH_URL'

2Fix

Build the URL with Google's client library, or fix the missing or encoded parameter. Use the client type that matches the flow: a Desktop app client for the installed-app flow.

# let the library build the URL, for example google-auth-oauthlib's flow.authorization_url()

3Verify

The consent screen loads for this client ID too.

# browser check

Confirmed by developers.google.com

Did this fix it?

How do I stop it coming back?

  • Use Google's current client libraries for each platform, so the flow and parameters stay valid.
  • Register one client per platform with the matching type (Web, Desktop, Android, iOS).
  • Never run sign-in inside a WebView.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.