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

Android: App crashes if the authentication dialog is canceled #17

Open
gkontokotsios opened this issue Oct 18, 2023 · 1 comment
Open

Comments

@gkontokotsios
Copy link

Hey Josh,

Thanks for this library! One issue I noticed is that my app is crashing when I click the "Cancel" button in the authentication dialog.

This is the exception:

I/flutter (10367): 2023-10-18 10:34:32.353207 - [INFO] AuthService: Launching authentication
V/CallbackHelper(10367): The Callback URI is: myApplicationScheme://auth0.url.com/android/my.package.name/callback
V/OAuthManager(10367): Using PKCE authentication flow
D/OAuthManager(10367): Using the following Authorize URI: https://auth0.url.com/authorize?...
I/flutter (10367): 2023-10-18 10:34:32.447434 - [INFO] LifeCycleHandler: SystemChannels> AppLifecycleState.inactive.  
D/TWAProviderPicker(10367): Found TWA provider, finishing search: com.android.chrome
I/flutter (10367): 2023-10-18 10:34:33.546646 - [INFO] LifeCycleHandler: SystemChannels> AppLifecycleState.paused.  
D/AndroidRuntime(10367): Shutting down VM
E/AndroidRuntime(10367): FATAL EXCEPTION: main
E/AndroidRuntime(10367): Process: my.package.name, PID: 10367
E/AndroidRuntime(10367): java.lang.RuntimeException: Unable to resume activity {my.package.name/com.auth0.android.provider.AuthenticationActivity}: java.lang.IllegalArgumentException: Unsupported value: 'io.flutter.embedding.android.FlutterActivity@73487e2' of type 'class io.flutter.embedding.android.FlutterActivity'
E/AndroidRuntime(10367): 	at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4824)
E/AndroidRuntime(10367): 	at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4857)
E/AndroidRuntime(10367): 	at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:54)
E/AndroidRuntime(10367): 	at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:45)
E/AndroidRuntime(10367): 	at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:176)
E/AndroidRuntime(10367): 	at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
E/AndroidRuntime(10367): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2253)
E/AndroidRuntime(10367): 	at android.os.Handler.dispatchMessage(Handler.java:106)
E/AndroidRuntime(10367): 	at android.os.Looper.loopOnce(Looper.java:201)
E/AndroidRuntime(10367): 	at android.os.Looper.loop(Looper.java:288)
E/AndroidRuntime(10367): 	at android.app.ActivityThread.main(ActivityThread.java:7870)
E/AndroidRuntime(10367): 	at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(10367): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
E/AndroidRuntime(10367): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
E/AndroidRuntime(10367): Caused by: java.lang.IllegalArgumentException: Unsupported value: 'io.flutter.embedding.android.FlutterActivity@73487e2' of type 'class io.flutter.embedding.android.FlutterActivity'
E/AndroidRuntime(10367): 	at io.flutter.plugin.common.StandardMessageCodec.writeValue(StandardMessageCodec.java:292)
E/AndroidRuntime(10367): 	at io.flutter.plugin.common.StandardMethodCodec.encodeErrorEnvelope(StandardMethodCodec.java:75)
E/AndroidRuntime(10367): 	at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler$1.error(MethodChannel.java:272)
E/AndroidRuntime(10367): 	at com.jfacoustic.flutter_auth0_client.FlutterAuth0ClientPlugin$login$1.onFailure(FlutterAuth0ClientPlugin.kt:76)
E/AndroidRuntime(10367): 	at com.jfacoustic.flutter_auth0_client.FlutterAuth0ClientPlugin$login$1.onFailure(FlutterAuth0ClientPlugin.kt:73)
E/AndroidRuntime(10367): 	at com.auth0.android.provider.OAuthManager.resume(OAuthManager.kt:85)
E/AndroidRuntime(10367): 	at com.auth0.android.provider.WebAuthProvider.resume(WebAuthProvider.kt:77)
E/AndroidRuntime(10367): 	at com.auth0.android.provider.AuthenticationActivity.deliverAuthenticationResult$auth0_release(AuthenticationActivity.kt:94)
E/AndroidRuntime(10367): 	at com.auth0.android.provider.AuthenticationActivity.onResume(AuthenticationActivity.kt:58)
E/AndroidRuntime(10367): 	at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1488)
E/AndroidRuntime(10367): 	at android.app.Activity.performResume(Activity.java:8197)
E/AndroidRuntime(10367): 	at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4814)
E/AndroidRuntime(10367): 	... 13 more

The exception seems to indicate that the issues is coming from:
FlutterAuth0ClientPlugin.kt:76

Flutter Doctor Output:

[✓] Flutter (Channel stable, 2.10.5, on macOS 14.0 23A344 darwin-arm, locale en-GB)
    • Flutter version 2.10.5 at /opt/homebrew/Caskroom/flutter@2/2.10.5/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 5464c5bac7 (1 year, 6 months ago), 2022-04-18 09:55:37 -0700
    • Engine revision 57d3bac3dd
    • Dart version 2.16.2
    • DevTools version 2.9.2

[!] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/myUser/Library/Android/sdk
    • Platform android-33, build-tools 34.0.0
    • Java binary at: /Library/Java/JavaVirtualMachines/temurin-11.jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment Temurin-11.0.19+7 (build 11.0.19+7)
    ✗ Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/macos#android-setup for more details.

[✓] Xcode - develop for iOS and macOS (Xcode 15.0)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • CocoaPods version 1.12.1

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[!] Android Studio (version 2022.3)
    • Android Studio at /Users/myUser/Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    ✗ Unable to find bundled Java version.
    • Try updating or re-installing Android Studio.

[✓] IntelliJ IDEA Ultimate Edition (version 2023.2.3)
    • IntelliJ at /Users/myUser/Applications/IntelliJ IDEA Ultimate.app
    • Flutter plugin version 75.1.4
    • Dart plugin version 232.10072.19

If you are willing to provide some feedback or tips, I will fix the issue myself and I will open a pull request. It's just that currently I'm not sure what is going on, is it maybe that result.error("AuthenticationException", exception.message, activity) is expecting an activity of type android.app.Activity and not one of type io.flutter.embedding.android.FlutterActivity?

Thanks in advance!

Best,
George

@gkontokotsios gkontokotsios changed the title Android: App crashes if Auth is canceled Android: App crashes if the authentication dialog is canceled Oct 18, 2023
@gkontokotsios
Copy link
Author

Hey Josh,

I think that the errormethod of the interface Interface MethodChannel.Result is expecting an Object errorDetails as its 3rd parameter and not an Activity.
The documentation states about the Object errorDetails:

errorDetails - Error details, possibly null. The details must be an Object type supported by the codec. For instance, if you are using StandardMessageCodec (default), please see its documentation on what types are supported.

This means that the issue here is quite easy to fix, we simply need to set the 3rd parameter to null. I'll create a pull request.

gkontokotsios added a commit to gkontokotsios/Flutter-Auth0 that referenced this issue Oct 18, 2023
…ject containing error details as its 3rd parameter and not an Activity
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant