aws-amplify / amplify-flutter

A declarative library with an easy-to-use interface for building Flutter applications on AWS.
https://docs.amplify.aws
Apache License 2.0
1.31k stars 243 forks source link

InvalidAccountTypeException thrown on windows #2260

Closed kmvignesh closed 1 year ago

kmvignesh commented 1 year ago

Description

using following dependencies

  amplify_flutter: ^1.0.0-next.0+3
  amplify_auth_cognito: ^1.0.0-next.0+3

Using below function user is able to login.

SignInResult res = await auth.signIn(
  username: loginModel.email,
  password: loginModel.pwd,
);

After login we are getting the token by calling fetchAuthSession function. While calling this getting following exception InvalidAccountTypeException(message: No identity pool registered for this account, recoverySuggestion: Register an identity pool using the CLI or set getAWSCredentials to false, underlyingException: null)

I tried hot restart. After hot restart, 2 times the function giving correct token, then again started giving same exception. The same code is working fine on Android and iOS

Categories

Steps to Reproduce

Try calling fetchAuthSession multiple times after signin

Screenshots

No response

Platforms

Android Device/Emulator API Level

API 31, API 32+

Environment

Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 3.3.4, on Microsoft Windows [Version 10.0.22621.674], locale en-IN)
[√] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
[√] Chrome - develop for the web
[√] Visual Studio - develop for Windows (Visual Studio Community 2022 17.3.6)
[√] Android Studio (version 2021.3)
[√] Connected device (3 available)
[√] HTTP Host Availability

Dependencies

Dart SDK 2.18.2
Flutter SDK 3.3.4
fdgv2 1.21.5+27

dependencies:
- amplify_api 1.0.0-next.0+3 [amplify_api_android amplify_api_ios amplify_core amplify_flutter aws_common collection flutter meta plugin_platform_interface]
- amplify_auth_cognito 1.0.0-next.0+5 [amplify_auth_cognito_android amplify_auth_cognito_dart amplify_auth_cognito_ios amplify_core amplify_flutter amplify_secure_storage async flutter flutter_web_plugins meta path plugin_platform_interface]
- amplify_flutter 1.0.0-next.0+3 [amplify_core amplify_datastore_plugin_interface amplify_flutter_android amplify_flutter_ios amplify_secure_storage aws_common collection flutter meta plugin_platform_interface]
- async 2.9.0 [collection meta]
- auto_size_text 3.0.0 [flutter]
- camera 0.9.8+1 [camera_android camera_avfoundation camera_platform_interface camera_web flutter flutter_plugin_android_lifecycle quiver]        
- characters 1.2.1
- charts_flutter 0.12.0 [charts_common collection flutter intl logging meta]
- collection 1.16.0
- connectivity_plus 2.3.6 [flutter connectivity_plus_platform_interface connectivity_plus_linux connectivity_plus_macos connectivity_plus_web connectivity_plus_windows]
- cupertino_icons 1.0.5
- device_info_plus 4.1.3 [flutter device_info_plus_platform_interface device_info_plus_macos device_info_plus_linux device_info_plus_web device_info_plus_windows]
- dotted_border 2.0.0+2 [flutter path_drawing]
- firebase_core 1.20.0 [firebase_core_platform_interface firebase_core_web flutter meta]
- firebase_crashlytics 2.8.5 [firebase_core firebase_core_platform_interface firebase_crashlytics_platform_interface flutter stack_trace]
- firebase_messaging 12.0.1 [firebase_core firebase_core_platform_interface firebase_messaging_platform_interface firebase_messaging_web flutter meta]
- flutter 0.0.0 [characters collection material_color_utilities meta vector_math sky_engine]
- flutter_image_compress 1.1.0 [flutter]
- flutter_inapp_notifications 0.0.3 [flutter]
- flutter_keyboard_visibility 5.3.0 [meta flutter_keyboard_visibility_platform_interface flutter_keyboard_visibility_web flutter]
- flutter_local_notifications 9.5.3+1 [clock flutter flutter_local_notifications_linux flutter_local_notifications_platform_interface timezone]   
- flutter_slidable 0.6.0 [flutter]
- flutter_svg 1.1.1+1 [flutter meta path_drawing vector_math xml]
- flutter_switch 0.3.2 [flutter]
- geolocator 8.2.1 [flutter geolocator_platform_interface geolocator_android geolocator_apple geolocator_web geolocator_windows]
- google_fonts 3.0.1 [flutter http path_provider crypto]
- google_mlkit_text_recognition 0.4.0 [flutter google_mlkit_commons]
- hypertrack_plugin 0.4.2 [flutter plugin_platform_interface]
- image 3.2.2 [archive meta xml]
- image_cropper 2.0.3 [flutter image_cropper_platform_interface image_cropper_for_web]
- image_picker 0.8.5+3 [flutter image_picker_android image_picker_for_web image_picker_ios image_picker_platform_interface]
- in_app_notification 1.1.2 [flutter]
- intl 0.17.0 [clock path]
- isolate_handler 1.0.1 [flutter flutter_isolate]
- json_annotation 4.6.0 [meta]
- jwt_decoder 2.0.1
- keyboard_actions 3.4.7 [flutter]
- linked_scroll_controller 0.2.0 [flutter]
- local_auth 2.1.0 [flutter intl local_auth_android local_auth_ios local_auth_platform_interface local_auth_windows]
- numeric_keyboard 1.1.0 [flutter]
- objectbox 1.6.0 [collection flat_buffers ffi meta path]
- objectbox_flutter_libs 1.6.0 [objectbox path_provider]
- package_info_plus 1.4.3+1 [flutter package_info_plus_platform_interface package_info_plus_linux package_info_plus_macos package_info_plus_windows package_info_plus_web]
- path 1.8.2
- path_provider 2.0.11 [flutter path_provider_android path_provider_ios path_provider_linux path_provider_macos path_provider_platform_interface path_provider_windows]
- path_provider_android 2.0.14 [flutter path_provider_platform_interface]
- path_provider_ios 2.0.11 [flutter path_provider_platform_interface]
- pendo_sdk 2.16.0 [flutter]
- permission_handler 9.2.0 [flutter meta permission_handler_android permission_handler_apple permission_handler_windows permission_handler_platform_interface]
- petitparser 5.0.0 [meta]
- rxdart 0.27.5
- scanbot_sdk 2.9.1-beta1 [logging json_annotation flutter]
- shared_preferences 2.0.15 [flutter shared_preferences_android shared_preferences_ios shared_preferences_linux shared_preferences_macos shared_preferences_platform_interface shared_preferences_web shared_preferences_windows]
- sprintf 6.0.2
- string_validator 0.3.0
- syncfusion_flutter_datepicker 19.4.56 [flutter intl syncfusion_flutter_core]
- url_launcher 6.1.5 [flutter url_launcher_android url_launcher_ios url_launcher_linux url_launcher_macos url_launcher_platform_interface url_launcher_web url_launcher_windows]
- uuid 3.0.6 [crypto]
- visibility_detector 0.3.2 [flutter]
- webview_flutter 3.0.4 [flutter webview_flutter_android webview_flutter_platform_interface webview_flutter_wkwebview]

transitive dependencies:
- amplify_api_android 1.0.0-next.0 [flutter]
- amplify_api_ios 1.0.0-next.0+1 [amplify_core flutter]
- amplify_auth_cognito_android 1.0.0-next.0+2 [flutter]
- amplify_auth_cognito_dart 0.1.6 [amplify_core amplify_secure_storage_dart async aws_common aws_signature_v4 built_collection built_value collection convert crypto fixnum http intl js json_annotation meta oauth2 path smithy smithy_aws stream_transform uuid worker_bee]
- amplify_auth_cognito_ios 1.0.0-next.0+3 [amplify_core flutter]
- amplify_core 1.0.0-next.0+1 [async aws_common aws_signature_v4 collection intl json_annotation logging meta uuid]
- amplify_datastore_plugin_interface 1.0.0-next.0+1 [amplify_core collection flutter meta]
- amplify_flutter_android 1.0.0-next.0 [flutter]
- amplify_flutter_ios 1.0.0-next.0+1 [amplify_core flutter]
- amplify_secure_storage 0.1.1 [amplify_secure_storage_dart async file flutter meta path path_provider]
- amplify_secure_storage_dart 0.1.1 [async aws_common built_collection built_value ffi file js meta path win32 worker_bee]
- archive 3.3.1 [crypto path]
- args 2.3.1
- aws_common 0.2.3 [async collection http2 js json_annotation logging meta stream_transform uuid]
- aws_signature_v4 0.2.2 [async aws_common collection convert crypto json_annotation meta path]
- boolean_selector 2.1.0 [source_span string_scanner]
- built_collection 5.1.1
- built_value 8.4.0 [built_collection collection fixnum meta]
- camera_android 0.9.8+3 [camera_platform_interface flutter flutter_plugin_android_lifecycle stream_transform]
- camera_avfoundation 0.9.8+2 [camera_platform_interface flutter stream_transform]
- camera_platform_interface 2.2.0 [cross_file flutter plugin_platform_interface stream_transform]
- camera_web 0.2.1+6 [camera_platform_interface flutter flutter_web_plugins stream_transform]
- charts_common 0.12.0 [collection intl logging meta vector_math]
- clock 1.1.1
- convert 3.0.2 [typed_data]
- crclib 3.0.0 [meta tuple]
- cross_file 0.3.3+1 [js meta]
- crypto 3.0.2 [typed_data]
- dbus 0.7.8 [args ffi meta xml]
- device_info_plus_linux 3.0.0 [device_info_plus_platform_interface file flutter meta]
- device_info_plus_macos 3.0.0 [device_info_plus_platform_interface flutter]
- device_info_plus_platform_interface 3.0.0 [flutter meta plugin_platform_interface]
- device_info_plus_web 3.0.0 [device_info_plus_platform_interface flutter_web_plugins flutter]
- device_info_plus_windows 4.1.0 [device_info_plus_platform_interface ffi flutter win32]
- fake_async 1.3.1 [clock collection]
- ffi 2.0.1
- file 6.1.2 [meta path]
- firebase_core_platform_interface 4.5.0 [collection flutter flutter_test meta plugin_platform_interface]
- firebase_core_web 1.7.1 [firebase_core_platform_interface flutter flutter_web_plugins js meta]
- firebase_crashlytics_platform_interface 3.2.11 [collection firebase_core flutter meta plugin_platform_interface]
- firebase_messaging_platform_interface 4.1.0 [firebase_core flutter meta plugin_platform_interface]
- firebase_messaging_web 3.1.0 [firebase_core firebase_core_web firebase_messaging_platform_interface flutter flutter_web_plugins js meta]        
- fixnum 1.0.1
- flat_buffers 2.0.5
- flutter_isolate 2.0.2 [flutter uuid]
- flutter_keyboard_visibility_platform_interface 2.0.0 [flutter meta plugin_platform_interface]
- flutter_keyboard_visibility_web 2.0.0 [flutter_keyboard_visibility_platform_interface flutter_web_plugins flutter]
- flutter_local_notifications_linux 0.4.2 [flutter flutter_local_notifications_platform_interface dbus path xdg_directories]
- flutter_local_notifications_platform_interface 5.0.0 [flutter plugin_platform_interface]
- flutter_plugin_android_lifecycle 2.0.7 [flutter]
- flutter_test 0.0.0 [flutter test_api path fake_async clock stack_trace vector_math async boolean_selector characters collection matcher material_color_utilities meta source_span stream_channel string_scanner term_glyph]
- flutter_web_plugins 0.0.0 [flutter js characters collection material_color_utilities meta vector_math]
- geolocator_android 3.1.8 [flutter geolocator_platform_interface]
- geolocator_apple 2.2.1 [flutter geolocator_platform_interface]
- geolocator_platform_interface 4.0.6 [flutter plugin_platform_interface vector_math meta]
- geolocator_web 2.1.6 [flutter flutter_web_plugins geolocator_platform_interface]
- geolocator_windows 0.1.1 [flutter geolocator_platform_interface]
- google_mlkit_commons 0.2.0 [flutter]
- http 0.13.4 [async http_parser meta path]
- http2 2.0.1
- http_parser 4.0.1 [collection source_span string_scanner typed_data]
- image_cropper_for_web 0.0.4 [flutter flutter_web_plugins image_cropper_platform_interface js]
- image_cropper_platform_interface 2.0.0 [flutter plugin_platform_interface http]
- image_picker_android 0.8.5+1 [flutter flutter_plugin_android_lifecycle image_picker_platform_interface]
- image_picker_for_web 2.1.8 [flutter flutter_web_plugins image_picker_platform_interface]
- image_picker_ios 0.8.5+6 [flutter image_picker_platform_interface]
- image_picker_platform_interface 2.5.0 [cross_file flutter http plugin_platform_interface]
- js 0.6.4
- local_auth_android 1.0.6 [flutter flutter_plugin_android_lifecycle intl local_auth_platform_interface]
- local_auth_ios 1.0.7 [flutter intl local_auth_platform_interface]
- local_auth_platform_interface 1.0.4 [flutter intl plugin_platform_interface]
- local_auth_windows 1.0.1 [flutter local_auth_platform_interface]
- logging 1.0.2
- matcher 0.12.12 [stack_trace]
- material_color_utilities 0.1.5
- meta 1.8.0
- nm 0.5.0 [dbus]
- oauth2 2.0.0 [collection crypto http http_parser]
- package_info_plus_linux 1.0.5 [package_info_plus_platform_interface flutter path]
- package_info_plus_macos 1.3.0 [flutter]
- package_info_plus_platform_interface 1.0.2 [flutter meta plugin_platform_interface]
- package_info_plus_web 1.0.5 [flutter flutter_web_plugins http meta package_info_plus_platform_interface]
- package_info_plus_windows 2.1.0 [package_info_plus_platform_interface ffi flutter win32]
- path_drawing 1.0.0 [vector_math meta path_parsing flutter]
- path_parsing 1.0.0 [vector_math meta]
- path_provider_linux 2.1.7 [ffi flutter path path_provider_platform_interface xdg_directories]
- path_provider_macos 2.0.6 [flutter path_provider_platform_interface]
- path_provider_platform_interface 2.0.4 [flutter platform plugin_platform_interface]
- path_provider_windows 2.1.3 [ffi flutter path path_provider_platform_interface win32]
- permission_handler_android 9.0.2+1 [flutter permission_handler_platform_interface]
- permission_handler_apple 9.0.4 [flutter permission_handler_platform_interface]
- permission_handler_platform_interface 3.7.0 [flutter meta plugin_platform_interface]
- permission_handler_windows 0.1.0 [flutter permission_handler_platform_interface]
- platform 3.1.0
- plugin_platform_interface 2.1.2 [meta]
- process 4.2.4 [file path platform]
- quiver 3.1.0 [matcher]
- rational 1.2.1
- retry 3.1.0
- sembast 3.2.0+1 [meta path synchronized]
- shared_preferences_android 2.0.12 [flutter shared_preferences_platform_interface]
- shared_preferences_ios 2.1.1 [flutter shared_preferences_platform_interface]
- shared_preferences_linux 2.1.1 [file flutter path path_provider_linux path_provider_platform_interface shared_preferences_platform_interface]   
- shared_preferences_macos 2.0.4 [flutter shared_preferences_platform_interface]
- shared_preferences_platform_interface 2.0.0 [flutter]
- shared_preferences_web 2.0.4 [flutter flutter_web_plugins shared_preferences_platform_interface]
- shared_preferences_windows 2.1.1 [file flutter path path_provider_platform_interface path_provider_windows shared_preferences_platform_interface]
- shelf 1.3.1 [async collection http_parser path stack_trace stream_channel]
- sky_engine 0.0.99
- smithy 0.1.1 [async aws_common built_collection built_value collection convert crypto fixnum http_parser intl json_annotation meta path retry shelf typed_data xml]
- smithy_aws 0.1.2 [aws_common aws_signature_v4 built_collection built_value collection crclib intl json_annotation meta path smithy xml]
- source_span 1.9.0 [collection path term_glyph]
- stack_trace 1.10.0 [path]
- stream_channel 2.1.0 [async]
- stream_transform 2.0.0
- string_scanner 1.1.1 [source_span]
- syncfusion_flutter_core 19.4.56 [vector_math flutter]
- synchronized 3.0.0+2
- term_glyph 1.2.1
- test_api 0.4.12 [async boolean_selector collection meta source_span stack_trace stream_channel string_scanner term_glyph matcher]
- timezone 0.8.0 [path]
- tuple 2.0.1
- typed_data 1.3.0 [collection]
- url_launcher_android 6.0.18 [flutter url_launcher_platform_interface]
- url_launcher_ios 6.0.17 [flutter url_launcher_platform_interface]
- url_launcher_linux 3.0.1 [flutter url_launcher_platform_interface]
- url_launcher_macos 3.0.1 [flutter url_launcher_platform_interface]
- url_launcher_platform_interface 2.1.0 [flutter plugin_platform_interface]
- url_launcher_web 2.0.13 [flutter flutter_web_plugins url_launcher_platform_interface]
- url_launcher_windows 3.0.1 [flutter url_launcher_platform_interface]
- vector_math 2.1.2
- webview_flutter_android 2.8.14 [flutter webview_flutter_platform_interface]
- webview_flutter_platform_interface 1.9.3 [flutter meta plugin_platform_interface]
- webview_flutter_wkwebview 2.7.5 [flutter path webview_flutter_platform_interface]
- win32 2.7.0 [ffi]
- worker_bee 0.1.1 [async aws_common built_collection built_value collection js meta path stack_trace stream_channel stream_transform]
- xdg_directories 0.2.0+1 [meta path process]
- xml 6.1.0 [collection meta petitparser]
- xxtea 2.1.0

Device

MSI

OS

Windows 11 22621.674

Deployment Method

Amplify CLI

CLI Version

No response

Additional Context

No response

Amplify Config

{
    "UserAgent": "aws-amplify-cli/2.0",
    "Version": "1.0",
    "auth": {
        "plugins": {
            "awsCognitoAuthPlugin": {
                "UserAgent": "aws-amplify/cli",
                "Version": "0.1.0",
                "IdentityManager": {
                    "Default": {}
                },
              "CognitoUserPool": {
                    "Default": {
                        "PoolId": "abc",
                        "AppClientId": "abcd",
                        "AppClientSecret": "abcde",
                        "Region": "abcde"
                    }
                },
                "Auth": {
                    "Default": {
                        "authenticationFlowType": "USER_SRP_AUTH"
                    }
                }
            }
        }
    },
     "api": {
      "plugins": {
        "awsAPIPlugin": {
          "api": {
            "endpointType": "GraphQL",
            "endpoint": "https://abcd.amazonaws.com/graphql",
            "region": "abcd",
            "authorizationType": "OPENID_CONNECT"
          }
        }
      }
    }
}
dnys1 commented 1 year ago

Hi @kmvignesh - can you share how you are calling fetchAuthSession? In vNext, when no identity pool is configured, you'll want to pass getAwsCredentials: false or just not pass that parameter:

final session = await Amplify.Auth.fetchAuthSession() as CognitoAuthSession;
kmvignesh commented 1 year ago

Hi @kmvignesh - can you share how you are calling fetchAuthSession? In vNext, when no identity pool is configured, you'll want to pass getAwsCredentials: false or just not pass that parameter:

final session = await Amplify.Auth.fetchAuthSession() as CognitoAuthSession;

Hey @dnys1 We have configured 'CognitoUserPool'. The same working fine in Android and iOS. Only on window we are getting this issue. If it's a configuration issue then how i was getting the token on hot-restart 🤔.

After login we need to get user details by calling another API. For calling that API i need to pass the idToken in the header. To get that token, After login immediately calling getIdToken function.

Future<String> getIdToken() async {
  String idToken = '';
  try {
    AuthSession res = await auth.fetchAuthSession(
        options: const CognitoSessionOptions(getAWSCredentials: true));
    idToken = (res as CognitoAuthSession).userPoolTokens!.idToken.raw;
  } on AuthException catch (e) {
    Log.logError('Error in getting Token \n Error Details: $e');
  }
  return idToken;
}
dnys1 commented 1 year ago

Thank you for sharing. Can you try replacing this line:

AuthSession res = await auth.fetchAuthSession(
     options: const CognitoSessionOptions(getAWSCredentials: true));

with this

AuthSession res = await auth.fetchAuthSession();

and let me know if that fixes the issue?

kmvignesh commented 1 year ago

I tried that. Its working. But its throwing exception when i kill and re-launch the app.

I generated exe file for windows using flutter build windows. After that i opened the app and logged in. Then i restarted my system and opened the app. That time it's giving exception No identity pool registered for this account and we are redirecting the user to login page. Now simply i close the app and reopen it. Now it's giving the token.

dnys1 commented 1 year ago

So you are still receiving the exception No identity pool registered for this account after making this change? Are you calling fetchAuthSession anywhere else?

When no identity pool is configured, passing getAWSCredentials: true to fetchAuthSession will result in this exception being thrown. This is different than the behavior on 0.x versions of Amplify. Please confirm you have removed all instances of getAWSCredentials: true and are still receiving the exception.

Jordan-Nelson commented 1 year ago

@kmvignesh - Can you confirm that there are no other locations where fetchAuthSession is called with getAWSCredentials: true?

Jordan-Nelson commented 1 year ago

@kmvignesh - If you are still facing this issue, can you please provide the info requested above? Thanks.

HuiSF commented 1 year ago

Hi @kmvignesh sorry we didn't hear back from you. Please feel free to reopen and follow up if you need further assistance.