Back

[Flutter] Error 400: redirect_uri_mismatch - Google sign-in error

  • 0
  • Android
  • Flutter
  • Apple
saksham
2 Apr, 2023, 14:08

I have hosted appwrite project locally, enabled google auth and did all the oauth consent process as per the documentation. Now I want to run the Flutter project on a real mobile device. To forward the port, I used ngrok and got an IP. I have confirmed that it's working fine.

Made OAuth Client API for Web application on a project in GCP Console, got the Client ID, Client Secret and passed it for enabling Google auth for Appwrite project. I have copied the redirect url from appwrite google auth console (which includes localhost/v1/....), and replaced the localhost part with ngrok url and put it as Google OAuth Client API redirect url.

Now, when I'm running the app with Flutter, it shows this 400: redirect_uri_mistmatch.

Can someone suggest any solution?

(P.S. The GCP project is in testing mode)

TL;DR
User is experiencing a '400: redirect_uri_mismatch' error when running a Flutter project with Google sign-in. They have followed the documentation for enabling Google auth for their Appwrite project, including setting up ngrok to forward the port. They have copied the redirect URL from the Appwrite Google auth console and replaced the 'localhost' part with the ngrok URL in the Google OAuth Client API redirect URL. The user is asking for a solution to the error. Possible solution: Double-check the redirect URI registered in the Google console matches the ngrok URL, including any additional paths. Make sure the GCP project is in testing
Drake
2 Apr, 2023, 16:26

Ngrok might be causing problems...what's the URL of the page when you get to the Google login screen?

saksham
2 Apr, 2023, 17:59

https://accounts.google.com/signin/oauth/error/v2?authError=ChVyZWRpcmVjdF91cmlfbWlzbWF0Y2gSsAEKWW91IGNhbid0IHNpZ24gaW4gdG8gdGhpcyBhcHAgYmVjYXVzZSBpdCBkb2Vzbid0IGNvbXBseSB3aXRoIEdvb2dsZSdzIE9BdXRoIDIuMCBwb2xpY3kuCgpJZiB5b3UncmUgdGhlIGFwcCBkZXZlbG9wZXIsIHJlZ2lzdGVyIHRoZSByZWRpcmVjdC...lzbWF0Y2g%3D&client_id=<MY_CLIENT_ID_FROM_GCP_PROJECT>.apps.googleusercontent.com

Drake
2 Apr, 2023, 18:56

Oh...this is after getting to the error page. Is there another page before?

Drake
2 Apr, 2023, 18:58

I'm trying to see the redirect URI that google receives

saksham
3 Apr, 2023, 01:54

Are you asking for the redirect URI I'm registering in the google console? If so it is: https://<NGROK_IP>/v1/account/sessions/oauth2/callback/google/642359fa4410a79b34ee

Drake
3 Apr, 2023, 02:03

No. I was asking for what actually gets sent to google

Drake
3 Apr, 2023, 02:06

In your browser on a desktop, open the network logger and then browse to.

TypeScript
<Endpoint>/account/sessions/oauth2/google?project=<project id>

Then, you should see the redirect URI sent to google

saksham
3 Apr, 2023, 02:58

I have a bit of dilemma here, does <Endpoint> refers to <NGROK_IP>?

Drake
3 Apr, 2023, 03:10

https://<ngrok ip>/v1

hortigado
13 Apr, 2023, 02:58

<activity android:name="com.linusu.flutter_web_auth_2.CallbackActivity" android:exported="true"> <intent-filter android:label="flutter_web_auth_2"> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:scheme="appwrite-callback-appid" />

hortigado
13 Apr, 2023, 02:59

you if added it in androidmanifest?

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more