Skip to content

[Auth] Hosted UI cancel on Android: OAuthErrorCode missing user_cancelled_authorize, error escapes as uncaught async #7077

Description

@erindolson

Description

Description

When a user cancels Cognito Hosted UI sign-in on Android, the callback returns
error=user_cancelled_authorize, but OAuthErrorCode doesn't include that enum value.
OAuthParameters.fromJson throws a built_value deserialization error instead of producing a
UserCancelledException. The same error is also re-raised through the auth state machine as an
unhandled async error.

I'd expect for user_cancelled_authorize to be mapped to a valid enum case and that no unhandled async exception should be emitted in this case.

Logs

Note: App-specific values have been redacted.
Flutter

I/flutter (28425): ----------------FIREBASE CRASHLYTICS----------------
I/flutter (28425): Deserializing to 'OAuthParameters' failed due to: Deserializing to 'OAuthErrorCode' failed due to: Invalid argument(s): user_cancelled_authorize
I/flutter (28425):
I/flutter (28425): package:built_value/src/built_json_serializers.dart 180:11                                BuiltJsonSerializers._deserialize
I/flutter (28425): package:built_value/src/built_json_serializers.dart 125:18                                BuiltJsonSerializers.deserialize
I/flutter (28425): package:built_value/src/built_json_serializers.dart 42:12                                 BuiltJsonSerializers.deserializeWith
I/flutter (28425): package:amplify_auth_cognito_dart/src/model/hosted_ui/oauth_parameters.dart 194:29        new OAuthParameters.fromJson
I/flutter (28425): package:amplify_auth_cognito/src/flows/hosted_ui/hosted_ui_platform_flutter.dart 101:31   HostedUiPlatformImpl.signIn
I/flutter (28425): ===== asynchronous gap ===========================
I/flutter (28425): package:amplify_core/src/state_machine/event.dart 42:45                                   new EventCompleter
I/flutter (28425): package:amplify_core/src/state_machine/state_machine.dart 186:19                          StateMachineManager.dispatch
I/flutter (28425): package:amplify_core/src/state_machine/state_machine.dart 413:15                          StateMachine.dispatch
I/flutter (28425): package:amplify_auth
I/flutter (28425): ----------------------------------------------------
I/flutter (28425): 

Android

D/AmplifyAuthCognitoPlugin: [onNewIntent] Got intent: Intent { act=android.intent.action.VIEW cat=[android.intent.category.BROWSABLE] dat=myapp://callback?error_description=Error+response+from+Identity+Provider;+error=user_cancelled_authorize&state=<redacted>&error=user_cancelled_authorize flg=0x14000000 cmp=com.example.myapp/com.example.myapp.MainActivity (has extras) }
D/AmplifyAuthCognitoPlugin: [onNewIntent] Handling intent with query parameters: {error_description=Error response from Identity Provider; error=user_cancelled_authorize, state=<redacted>, error=user_cancelled_authorize} (signInResult=com.amazonaws.amplify.amplify_auth_cognito.AtomicResult@7c41db6, signOutResult=null)
D/AmplifyAuthCognitoPlugin: handleSignInResult: {error_description=Error response from Identity Provider; error=user_cancelled_authorize, state=<redacted>, error=user_cancelled_authorize} (signInResult=com.amazonaws.amplify.amplify_auth_cognito.AtomicResult@7c41db6)
D/AmplifyAuthCognitoPlugin: [onNewIntent] Got intent: Intent { flg=0x10000000 cmp=com.example.myapp/com.example.myapp.MainActivity (has extras) }
D/AmplifyAuthCognitoPlugin: [onNewIntent] Cancelling current operation
D/AmplifyAuthCognitoPlugin: [cancelCurrentOperation] Canceling with state: signInResult=null, signOutResult=null

Uncaught Async Error Stack where the debugger pauses, even with the try/catch

Error._throw                                  dart:core-patch/errors_patch.dart 27:68
Error.throwWithStackTrace                     dart:core/errors.dart 120:5
_rootHandleError.<anonymous closure>          dart:async/zone_root.dart 22:11
_microtaskLoop                                dart:async/schedule_microtask.dart 40:35
_startMicrotaskLoop                           dart:async/schedule_microtask.dart 49:5

Platforms

Android confirmed, not sure how to test with iOS since the Apple sign in flow is different on iOS.

Versions

Flutter Version
3.41.8

Amplify Flutter Version
amplify_flutter: 2.10.0
amplify_auth_cognito: 2.10.0
amplify_auth_cognito_dart: 0.11.19
amplify_core: 2.10.1

Categories

  • Analytics
  • API (REST)
  • API (GraphQL)
  • Auth
  • Authenticator
  • DataStore
  • Notifications (Push)
  • Storage

Steps to Reproduce

On Android,

  1. Configure Cognito Hosted UI with Apple.
  2. On Android, call Amplify.Auth.signInWithWebUI(provider: AuthProvider.apple) inside a try/catch.
  3. After submitting your credentials you see a page by Apple that says "Do you want to continue using {App Name} with your Apple Account "{email}"?, and hit "cancel" rather than "continue".
  4. Observe the deserialization error (see Logs) instead of UserCancelledException, and the
    debugger pausing on an uncaught exception even though the call is awaited inside try/catch.

Screenshots

No response

Platforms

  • iOS
  • Android
  • Web
  • macOS
  • Windows
  • Linux

Flutter Version

3.41.8

Amplify Flutter Version

2.10.0

Deployment Method

Custom Pipeline

Schema

Metadata

Metadata

Assignees

No one assigned

    Labels

    authIssues related to the Auth CategorybugSomething is not working; the issue has reproducible steps and has been reproduced

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions