flutter_appauth icon indicating copy to clipboard operation
flutter_appauth copied to clipboard

Some user cant login with google, redirect issue

Open alibaltschun opened this issue 1 year ago • 12 comments

Issue: Google Login Failing for Some Users on Flutter App Description: For the past month, many users have reported that they cannot log in using Google on the app. Some users are redirected to the Google login page, while others are stuck in a loading state after selecting their Gmail account. However, the issue is not reproducible on my device —I've tested on multiple devices, and Google login works without issues. Despite this, over 1000 users are unable to log in.

Error Details: The error sent to Sentry is:


PlatformException
FlutterAppAuthUserCancelledException{platformErrorDetails: FlutterAppAuthPlatformErrorDetails(type: 0,
 code: 1,
 error: null,
 errorDescription: User cancelled flow,
 errorUri: null,
 domain null,
rootCauseDebugDescription: null,
 errorDebugDescription: AuthorizationException: {"type":0,"code":1,"errorDescription":"User cancelled flow"})}

Code: Here’s the relevant code that handles the Google login flow:

dart Copy code


Future<bool> login() async {
  final AuthorizationTokenRequest authorizationTokenRequest;

  try {
    authorizationTokenRequest = AuthorizationTokenRequest(
      GoogleClientID(),
      GoogleRedirectUrl(),
      issuer: GOOGLE_ISSUER,
      scopes: ['openid', 'email', 'profile'],
    );

    // Requesting the auth token and waiting for the response
    final AuthorizationTokenResponse? result =
        await _appAuth.authorizeAndExchangeCode(
      authorizationTokenRequest,
    );

    // Taking the obtained result and processing it
    return await _handleAuthResult(result);
  } on PlatformException catch (e) {
    Sentry.captureException(e, stackTrace: StackTrace.current);

    // Handle specific platform exceptions
    if (e.code == 'CANCELED') {
      toast('User canceled the login!');
    } else if (e.code == 'NETWORK_ERROR') {
      toast('No internet connection!');
    } else {
      toast('Platform Error: ${e.message}');
    }
    return false;
  } catch (e) {
    Sentry.captureException(e, stackTrace: StackTrace.current);
    toast('Failed with Error : $e');
    return false;
  }
}

Steps Taken to Resolve: Device Testing: Tried on multiple devices including: Samsung device iPhone 8 iPhone 12 Android tablet 2 of my friend's Android phones 2 simulators The login works fine on all devices.

Error Capture: The error captured by Sentry is FlutterAppAuthUserCancelledException, indicating that the user canceled the login flow. Package Update: I’ve updated all dependencies to the latest versions, but the problem persists.

Dependencies: Here are the dependencies being used:


cupertino_icons: ^1.0.2
flutter_appauth: ^6.0.2
http: ^1.1.0
flutter_secure_storage: ^9.0.0
google_fonts: ^5.1.0
dots_indicator: ^3.0.0
flutter_riverpod: ^2.4.0
intl: ^0.18.1
flutter_lints: ^2.0.3
qr_flutter: ^4.1.0
jwt_decoder: ^2.0.1
get: ^4.6.6
flutter_easyloading: ^3.0.5
flutter_launcher_icons: ^0.13.1
flutter_dotenv: ^5.1.0
package_info: ^2.0.2
url_launcher: ^6.2.4
timetable_view: ^0.3.0
the_apple_sign_in: ^1.1.1
carousel_slider: ^5.0.0
firebase_core: ^2.24.2
firebase_messaging: ^14.7.10
flutter_local_notifications: ^17.0.0
sentry_flutter: ^8.10.1

Flutter version: 3.24.5 (Stable channel)

Problem: Despite working on my devices and several other devices, over 1000 users are experiencing the issue. This suggests that the problem may be related to specific devices, OS versions, or configurations that I am unable to replicate.

Expected Behavior: The Google login should work without errors, and users should be able to authenticate and access the app.

Actual Behavior: Some users are redirected to the Google page or get stuck in a loading loop, leading to a cancellation of the login process. Sentry logs show that the users are cancelling the login flow.

Request for Help: I’m unable to reproduce the issue, and I need assistance in diagnosing why this issue is occurring for some users but not on my devices. Any insights or suggestions to help resolve this would be appreciated!

alibaltschun avatar Dec 03 '24 17:12 alibaltschun

We're experiencing the same issue.

say-when avatar Mar 29 '25 18:03 say-when

@say-when do you use cloudflare? i still face the issue,do you think it happend bacause some user did not support TLS?

alibaltschun avatar Apr 02 '25 03:04 alibaltschun

I am building a new app and it has happening to me also

satyam7world avatar Apr 03 '25 14:04 satyam7world

We never had the taskAffinity in our manifest. Adding this to the AndroidManifest.xml fixed the problem for me. <activity xmlns:tools="http://schemas.android.com/tools" android:name="net.openid.appauth.AuthorizationManagementActivity" android:launchMode="singleInstance" tools:replace="android:launchMode" />

say-when avatar Apr 03 '25 16:04 say-when

where do you put that code @say-when ? but when i saw the thread, they say it should be removed, but you said you put it in fix the problem.

alibaltschun avatar Apr 04 '25 01:04 alibaltschun

where do you put that code @say-when ? but when i saw the thread, they say it should be removed, but you said you put it in fix the problem.

I put it in the AndroidManifest.xml file inside the < application> after the .MainActivity < activity> block . The oAuth began to work again and redirected back to the app.

say-when avatar Apr 04 '25 05:04 say-when

there is some user that use non secure default web browser that make login failed, after guide them to download chrome, and set it as default browser, they can login.

so is that any way to force using secure web browser?

alibaltschun avatar Apr 07 '25 11:04 alibaltschun

We never had the taskAffinity in our manifest. Adding this to the AndroidManifest.xml fixed the problem for me. <activity xmlns:tools="http://schemas.android.com/tools" android:name="net.openid.appauth.AuthorizationManagementActivity" android:launchMode="singleInstance" tools:replace="android:launchMode" />

Spent countless hours, nothing worked on Android but this solved the issue. This scares me even more, as its not explaining to me what happening here.

esodot avatar Apr 25 '25 11:04 esodot

@esodot and @say-when which version of flutter and appauth do you use?

alibaltschun avatar Apr 25 '25 23:04 alibaltschun

@esodot and @say-when which version of flutter and appauth do you use?

Hi, flutter_appauth: ^9.0.0 Flutter 3.29.1

esodot avatar Apr 28 '25 15:04 esodot

We never had the taskAffinity in our manifest. Adding this to the AndroidManifest.xml fixed the problem for me. <activity xmlns:tools="http://schemas.android.com/tools" android:name="net.openid.appauth.AuthorizationManagementActivity" android:launchMode="singleInstance" tools:replace="android:launchMode" />

We also solved the problem adding this tag to the manifest for a Keyloack authentification. Looks like multiple instance of AuthorizationManagementActivity are running and that makes the redirection failed ?

Ezor avatar Aug 29 '25 08:08 Ezor