Back

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

  • 0
  • Android
  • Flutter
Gogi~
12 Nov, 2023, 22:27

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

TL;DR
The user is experiencing an issue with the login flow in their Flutter app. The issue occurs when attempting to log in with 2FA on an account that has the Authenticator app on the same device. The login flow is automatically canceled when the user switches to the Authenticator app. The user has tried different solutions and launch modes, but the problem persists. The issue has been documented on GitHub, and the user is seeking assistance. Currently, there is no solution provided, but the user plans to continue investigating and posting updates on GitHub.
Gogi~
12 Nov, 2023, 22:29

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

Drake
12 Nov, 2023, 22:33

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

https://gitlab.com/metalwings/appwrite-flutter-oauth2-demo/-/blob/main/android/app/src/main/AndroidManifest.xml?ref_type=heads#L9

Gogi~
12 Nov, 2023, 22:34

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

Gogi~
12 Nov, 2023, 22:56

Unfortunately the problem is still there, even with different launchMode

i tried standard / singleTop / singleTask and singleInstance

Gogi~
14 Nov, 2023, 19:56

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.

Gogi~
14 Nov, 2023, 19:59

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

Drake
14 Nov, 2023, 21:06

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

Drake
14 Nov, 2023, 21:06

@dlohani any ideas about this?

dlohani
19 Nov, 2023, 06:24

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

Gogi~
19 Nov, 2023, 15:37

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
Gogi~
19 Nov, 2023, 15:45

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

Gogi~
19 Nov, 2023, 16:21

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

D5
19 Nov, 2023, 16:21

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

D5
19 Nov, 2023, 16:22

Also why combinig OAuth + 2FA?

Gogi~
19 Nov, 2023, 16:23

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

Gogi~
19 Nov, 2023, 16:24

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

D5
19 Nov, 2023, 16:24

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

Gogi~
19 Nov, 2023, 16:24

yes

D5
19 Nov, 2023, 16:25

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

D5
19 Nov, 2023, 16:26

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

Gogi~
19 Nov, 2023, 16:27

Smart! I will try this out

Gogi~
19 Nov, 2023, 16:45

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.

TypeScript
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");
}
Gogi~
19 Nov, 2023, 16:46

Thank you for the help and ideas

Gogi~
19 Nov, 2023, 16:50

I've documented the workaround in github. This thread can be closed.

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