Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Bug Report: [Android] Switching to any authenticator app while creating a Google OAuth Session breaks the login flow #181

Open
2 tasks done
metalwings opened this issue Nov 14, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@metalwings
Copy link

metalwings commented Nov 14, 2023

👟 Reproduction steps

Requirements

  • Google Account with an activated 2FA (two-factor-authentication) option
  • An android device which is logged into the same google account
  • appwrite project with Google OAuth setup

Reproduction

  1. Enable Google 2FA and make sure you are using an android device
  2. Login into your google account through createOAuth2Session(provider: "google")
  3. You switch to your 2FA application
  4. After confirming your 2FA, the login window is automatically closed but you're not logged in

Further information

Article how to add Google 2FA to your account: https://support.google.com/accounts/answer/185839

I've created a minimal reproduction repository:
https://gitlab.com/metalwings/appwrite-flutter-oauth2-demo

In my case the default "is this you?" screen is automatically shown by android as soon as I try to login into my account.

👍 Expected behavior

Switching to any authenticator app doesn't break the login flow.
Users should be able to switch to other app (in my case the default android auth by google, check my 2FA Code (or press "that's me") and login after I've completed the 2FA flow

👎 Actual Behavior

The login flow is cancelled due to loss of app focus.
An exception is thrown:

E/flutter ( 6554): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(CANCELED, User canceled login, null, null)
E/flutter ( 6554): #0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:652:7)
E/flutter ( 6554): #1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:310:18)
E/flutter ( 6554): <asynchronous suspension>
E/flutter ( 6554): #2      FlutterWebAuth2MethodChannel.authenticate 
(package:flutter_web_auth_2_platform_interface/method_channel/method_channel_flutter_web_auth_2.dart:16:7)

🎲 Appwrite version

Version 2.0.x
Appwrite Cloud
SDK Version 11

💻 Operating system

Linux

🧱 Your Environment

Problem can be reproduced in the appwrite cloud version

👀 Have you spent some time to check if this issue has been raised before?

  • I checked and didn't find similar issue

🏢 Have you read the Code of Conduct?

@metalwings metalwings added the bug Something isn't working label Nov 14, 2023
@metalwings
Copy link
Author

@metalwings metalwings changed the title 🐛 Bug Report: Switching to any authenticator app while creating a Google OAuth Session breaks the login flow 🐛 Bug Report: [Android] Switching to any authenticator app while creating a Google OAuth Session breaks the login flow Nov 19, 2023
@metalwings
Copy link
Author

metalwings commented Nov 19, 2023

Tested on iOS.
Everything works there, because the sign-in window behavior is different.

Also found a new clue: For some reason, the browser window "Sign in with Google" is closed automatically as soon as I try to switch to another app.

Screen_Recording_20231119_163813_One.UI.Home.mov

This behavior can be reproduced on different physical Android devices and on emulated devices as well.

@metalwings
Copy link
Author

metalwings commented Nov 19, 2023

Workaround:

  • Initialize the OAuth Session manually by triggering flutter_web_auth_2
  • After successful login, trigger the AppWrite OAuth Flow
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");
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant