Hi,
I have been trying to log users into my Chrome extension with chrome.identity.launchWebAuthFlow, yet I keep getting the following error: Error 400: redirect_uri_mismatch (see screenshot below).
Context
function login() { const manifest = chrome.runtime.getManifest(); if (!manifest.oauth2?.scopes) throw new Error('No OAuth2 scopes defined in the manifest file'); const url = new URL('https://accounts.google.com/o/oauth2/auth'); url.searchParams.set('client_id', manifest.oauth2.client_id); url.searchParams.set('response_type', 'id_token'); url.searchParams.set('access_type', 'offline'); url.searchParams.set('redirect_uri', chrome.identity.getRedirectURL()); url.searchParams.set('scope', manifest.oauth2.scopes.join(' ')); return new Promise((resolve, reject) => chrome.identity.launchWebAuthFlow( { url: url.href, interactive: true, }, async (redirectedTo) => { if (chrome.runtime.lastError) { reject(`Could not login - ${chrome.runtime.lastError.message}`); } else { const url = new URL(redirectedTo!); const params = new URLSearchParams(url.hash); resolve(params.get('id_token')) } }, ), ); }
{ "manifest_version": 3, "permissions": ["identity", ...], "oauth2": { "client_id": "<client ID>", "scopes": ["openid", "email", "profile"] }, ... }
What else I have tried
What am I missing?
Thanks for your help!
All right I made it work with these four changes:
Hope this helps... the two things that remain a mistery to me are:
1. Why doesn't the Chrome extension Oauth Client ID work properly?
2. Why doesn't chrome.identity.getRedirectURL() work properly (it returns a trailing slash, and I could only make it work without the trailing slash)?
I did the first step but it only worked when I included the trailing slash.
Thanks @larryco it worked.
Thanks, @larryco , it works in my product. I use Edge, and I didn't setup the Manifest Key.
Is there any way to make it work with chrome extension client - without using Web application client?
I don't know, but if you make it work with the chrome extension client, I'd love to know how.