Skip to content
Init is coming / May 19 - 23
Back

[SOLVED] OAuth With Google & Flutter

  • 0
  • Flutter
  • Cloud
Adam ONeill
10 Dec, 2024, 18:31

Hi all,

I'm trying to sign in with google and it all goes swimmingly until the call back. I get a new user created on the appwrite dashboard however the flutter app remains on the appwrite hoted success page (Black screen). I'd like this is come back to the app and log the user in.

Here is my signInWithProvider funciton which lives my AuthAPI

TypeScript
signInWithProvider({required OAuthProvider provider}) async {
    try {
      final session = await account.createOAuth2Session(provider: provider);
      await Future.delayed(const Duration(microseconds: 500));
      _currentUser = await account.get();
      _status = AuthStatus.authenticated;
      return session;
    } finally {
      notifyListeners();
    }
  }
TL;DR
Developers were having trouble implementing OAuth with Google and Flutter. Another developer provided helpful documentation and links for OAuth setup with Apple. The issue was resolved by making corrections in the Android manifest file. The initial problem was with remaining on the Appwrite hosted success page instead of returning to the app after Google sign-in. The provided `signInWithProvider` function was shared for reference.
Darshan Pandya
10 Dec, 2024, 18:33

Iirc the success page should trigger a deep link to your app. Any errors, warnings? Not sure if flutter side requires deeplinks logic.

Adam ONeill
10 Dec, 2024, 18:34

Sorry, just realised those parameters were only there for testing. I didnt have them in originially

D5
10 Dec, 2024, 18:34

Do you have added this to the android manifest file?

TypeScript
    <!-- Add this inside the `<application>` tag, along side the existing `<activity>` tags -->
    <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-[PROJECT_ID]" />
      </intent-filter>
    </activity>
Adam ONeill
10 Dec, 2024, 18:34

Yep I do!

D5
10 Dec, 2024, 18:34

And changed the projectID?

D5
10 Dec, 2024, 18:34

This is happening in android?

Adam ONeill
10 Dec, 2024, 18:35

Should that project id be in the appwrite project id?

D5
10 Dec, 2024, 18:39

Yes

D5
10 Dec, 2024, 18:39

You had there the app id?

Adam ONeill
10 Dec, 2024, 18:39

bare with hang on

Adam ONeill
10 Dec, 2024, 18:41

I was being really silly and miss typed it. Thanky you so much for the speedy response!!

Adam ONeill
10 Dec, 2024, 18:47

This is working now. Feel free to close the ticket!

D5
10 Dec, 2024, 18:47

No worries! We are here to help 🙂

Adam ONeill
10 Dec, 2024, 18:47

Could you point me where to start for apple's oauth process? I cant find your docs

D5
10 Dec, 2024, 18:47

Great! If you find any other issues, create a new post and we will help again 😄

D5
10 Dec, 2024, 18:49

Sure. In the case of apple it's somewhat similar to Google: https://appwrite.io/docs/references/cloud/client-flutter/account#createOAuth2Session

Hope this tutorial helps too with the config: https://appwrite.io/integrations/oauth-apple

D5
10 Dec, 2024, 18:50

[SOLVED] OAuth With Google & Flutter

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