
tl;dr of the problem is basically: when you log in into an account that has 2FA and the Authenticator is on the same device, the login flow gets aborted as soon as the user switches to the authenticator app

and it doesn't have to be any special authenticator app. On my phone, the default google authentication screen is shown as soon as I try to log in

So this might be related to the launch mode option in your manifest. Maybe you can play around with the different options.

Okay, thanks for the idea. I will check the different options. Will let you know in a bit

Unfortunately the problem is still there, even with different launchMode
i tried standard / singleTop / singleTask and singleInstance

Hey @Steven
I've spent quite some time trying to debug and fix the issue and it's definitely harder to fix than I thought.
I won't have enough time this week to invest into this problem, although it's important for the release of my app. It might be quite challenging to reproduce the problem, but I do think that actually a lot of people will have it.
Before the mods ask if this has been resolved, I'm opening an issue in the sdk-for-flutter github, so you can close this thread. https://github.com/appwrite/sdk-for-flutter/issues/181
I'll be trying to fix the issue on the weekend and will post my progress there.
If someone of the appwrite team has time to look into it with me, I'm open to a pair programming sessions, just hit me up.

[UNRESOLVED] Yet another PlatformException(CANCELED, User canceled login, null, null)

PlatformException(CANCELED, User canceled login, null, null)

@dlohani any ideas about this?

Not much, havent tested with 2FA. But from the info it's clear the auth flow is cancled when app switch occurs that might be SDK level issue, will need to test

Good and bad news 😄 Good things first: I was able to test the complete auth flow on iOS and can confirm now that the bug can only be reproduced on android. No problems with iOS.
Bad: still no clue what/which method call exactly causes the problem in order to think about the solution, but I found a new clue. For some reason, the browser window that is opened by url_launcher
in flutter_web_auth_2
is closed automatically as soon as I try to switch to other app. This action the actual "User canceled login"-Exception.
I'm going to send a video in a bit.
Next steps:
- Find what's causing the browser window to close
- Test on few more real android devices
- Test on android emulator

Here you can clearly see how the "Sign-In with Google"-Window is closed. I'm not closing it by myself. It's automatically closed as soon as I try to switch to another app.
This happens when the Google 2FA Push notification opens the Google Prompts window

Problem can be reproduced on emulated devices: Pixel XL, Nexus 6 Tested on my old physical OnePlus 6. Also reproducable.

Because you're not supposed to change windows meanwhile it's opened

Also why combinig OAuth + 2FA?

@D5 users can enable 2FA on their google account for more security

there are different options - either SMS, 2FA with Authenticator or Google Prompts (the one that I've shown in my very first screenshot)

Okay, I understand it now, so if you click the push notification it gets closed

yes

An alternative meanwhile is login previously on chrome so you will have a session there in the webview.

So when clicking the button you could redirect first to google login page in a webview and once completed the flow, redirect back to the app and then start Appwrite OAuth flow

Smart! I will try this out

Yeah I think this will do the job. Logging in through a webview (launched by url_launcher
) creates the session and afterwards I'm able to login.
2FA didn't break the Auth Flow, I was able to switch between the apps as much as I want.
I'm still quite curious what causes the automatic close of the windows. Internally the sdk-for-flutter
is using flutter_web_auth_2
which uses url_launcher
to open the URLs.
String provider = "google";
String projectId = "<YOUR PROJECT ID HERE>";
String host = "https://cloud.appwrite.io/v1";
String url = "$host/account/sessions/oauth2/$provider?project=$projectId";
try {
await FlutterWebAuth2.authenticate(
url:url,
callbackUrlScheme: "appwrite-callback-$projectId");
await widget.account.createOAuth2Session(provider: provider);
} catch (e) {
print("Do nothing or handle exception, because the login was not successful");
}

Thank you for the help and ideas

I've documented the workaround in github. This thread can be closed.
Recommended threads
- Flutter Google Auth (Access blocked: Thi...
It is working fine on web platform, but on Flutter I'm getting this error. Any option to fix, or this issue with AppWrite and need to use different option? Ac...
- android kotlin error updatePhone
package vasu.apps.schooldashboard.Services import android.util.Log import io.appwrite.Client import io.appwrite.ID import io.appwrite.exceptions.AppwriteExcept...
- Relationships restricted to a max depth ...
When I do query like: ``` await _databases.listDocuments( databaseId: AppwriteConfig.DATABASE_ID, collectionId: AppwriteConfig.SERVICES_COLLECTI...
