supabase: Google Sign-In Error in Chrome Extension: Invalid Request (Error 400: redirect_uri_mismatch)

When attempting to sign in with Google in a Chrome extension using Supabase authentication, the following error occurs:

Access blocked: This app's request is invalid
You can't sign in because this app sent an invalid request. You can try again later, or contact the developer about this issue.
Error 400: redirect_uri_mismatch

Reproduction Repository

I have created a minimal repository to reproduce this issue: https://github.com/btahir/vite-supabase-chrome-extension

This repository contains a simplified Chrome extension built with Vite and Supabase, demonstrating the Google Sign-In error.

Steps to Reproduce

  1. Clone the reproduction repository: git clone https://github.com/btahir/vite-supabase-chrome-extension
  2. Follow the setup instructions in the repository’s README
  3. Load the extension in Chrome
  4. Attempt to sign in using Google authentication
  5. Observe the error message described above

Expected Behavior

The sign-in process should complete successfully, allowing the Chrome extension to authenticate with Supabase using Google Sign-In.

Actual Behavior

The sign-in process fails with an invalid request error, specifically a redirect_uri_mismatch.

  1. Are there specific steps or configurations needed for Google Sign-In in a Chrome extension when using Supabase?
  2. Does Supabase have any documentation or examples specifically for Chrome extension integration?
  3. Are there known limitations or extra steps required for OAuth flows in Chrome extensions that might be affecting the Supabase integration?
  4. How should the redirect URI be configured in the Google Cloud Console for a Chrome extension?

Specific Error Details

The full error message includes the following details:

Error 400: redirect_uri_mismatch
Request details: flowName=GeneralOAuthFlow

Any assistance in resolving this Chrome extension-specific authentication issue would be greatly appreciated. Thank you!

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 7
  • Comments: 20 (3 by maintainers)

Commits related to this issue

Most upvoted comments

Why is this closed @Hallidayo ? The docs should be updated because the same problem still does exist. It looks like it’s not really possible to perform a web authentication flow for a Chrome extension.

Hi all, We’re going to close this one due to inactivity. Please feel free to reopen if you’re still having issues here or open a new issue.

I have the same issue…

@btahir I have followed the chrome extension instructions however they do not work and I am still getting the same Error 400: redirect_uri_mismatch error. I will attempt the solutions provided above however I believe that the supabase documentation on goggle auth with extension is not extensive.

@gunayanil I agree I think the docs at the very least need to be updated.

yes – we did end up getting it working.

the redirect_uri_mismatch was solved for me by following the Manifest Key Stack Overflow instructions I mentioned above. once that was working, I was able to implement:

export async function signInWithGoogle(): Promise<void> {
  const redirectURL = chrome.identity.getRedirectURL();
  const { data, error } = await supabase.auth.signInWithOAuth({
    provider: 'google',
    options: {
      redirectTo: redirectURL,
    },
  });
  if (error) throw error;

  await chrome.tabs.create({ url: data.url });
}

ultimately login with Apple was even more of a headache, so I got pretty fed up with the extension and put it on pause for now.

creating a web application client and adding redirecturi to it matching the one in code made it work for me.

Seems like using launchWebAuthFlow with chrome extension Client type is not possible

https://groups.google.com/a/chromium.org/g/chromium-extensions/c/9jADkbZcdYE

Yes, indeed the docs are incorrect. As you need to do a workaround with the web app instead of “Chrome extension”.

FWIW, with the Chrome Extension the Chrome identity API provides, chrome.identity.getAuthToken which can be used to get the access_token. If only Supabase could sign in using an access_token instead of relying on an “id_token”, it would be much simpler experience here.

chrome.identity.getAuthToken({ interactive: true }, async (access_token) => {

  const { data, error } = await supabase.auth.signInWithIdToken({
    provider: 'google',
    token: access_token, // This does NOT work, because supabase expects an Id Token.
  })
});

I found this comment had instructions that ultimately fixed this for me – the key points being to find the manifest key from the developer console, as well as adding a Web endpoint with the redirect URL included in the credentials. copying from SO:

I used a Client ID for Web application rather than for Chrome extension and added https://<extension_id>.chromiumapp.org (without trailing slash) to the list of Authorized redirect URIs

To make this work locally, I added the manifest key to my extension - Google seems to check the extension ID at runtime as part of launchWebAuthFlow

I replaced const params = new URLSearchParams(url.hash) with const params = new URLSearchParams(url.hash.replace(‘#’, ‘’)). The reason is url.hash looks like #id_token=<id_token>&…, so the search param key looks like %23id_token and params.get(‘id_token’) returns undefined.

however, now that it’s working, I’m running into the exact same challenges described here that basically cause the login to fail whenever you click outside of the extension. might be worth starting with the strategy he outlines instead (that’s what I’m hoping to implement next).