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.33k stars 247 forks source link

Remember Device after social login not working #1515

Open irisk29 opened 2 years ago

irisk29 commented 2 years ago

Description

Hello, I want to allow only one sign in for user in my app, I found here https://github.com/aws-amplify/amplify-flutter/issues/1206 a suggested solution to use the RememberDevice feature.

The user logged in and then I wanted to remember the device but I encountered an error: flutter: Remember device failed with error: DeviceNotTrackedException(message: This device does not have an id, either it was never tracked or previously forgotten., recoverySuggestion: Call remeberDevice to track the device, underlyingException: The operation couldn’t be completed. (AmplifyPlugins.AWSCognitoAuthError error 17.))

I run the amplify auth console and activated the remember device feature in cognito. Is there something that I'm missing?

Categories

Steps to Reproduce

this code produces the error for me:

`await Amplify.Auth.signInWithWebUI(provider: authProvider);

try { await Amplify.Auth.rememberDevice(); var d = await Amplify.Auth.fetchDevices(); for (var dd in d) { print("device name: ${dd.name}"); } print('Remember device succeeded'); } on Exception catch (e) { print('Remember device failed with error: $e'); }`

Screenshots

My cognito: Screen Shot 2022-04-07 at 14 58 53

Platforms

Environment

[✓] Flutter (Channel stable, 2.10.4, on macOS 12.3.1 21E258 darwin-x64, locale en-IL)
[✗] Android toolchain - develop for Android devices
    ✗ Unable to locate Android SDK.
      Install Android Studio from: https://developer.android.com/studio/index.html
      On first launch it will assist you in installing the Android SDK components.
      (or visit https://flutter.dev/docs/get-started/install/macos#android-setup for detailed instructions).
      If the Android SDK has been installed to a custom location, please use
      `flutter config --android-sdk` to update to that location.

[✓] Xcode - develop for iOS and macOS (Xcode 13.3)
[✓] Chrome - develop for the web
[!] Android Studio (not installed)
[✓] IntelliJ IDEA Ultimate Edition (version 2021.2.3)
[✓] VS Code (version 1.66.0)
[✓] VS Code (version 1.62.3)
[✓] Connected device (2 available)
[✓] HTTP Host Availability

Dependencies

Dart SDK 2.16.2
Flutter SDK 2.10.4

dependencies:
- address_search_field 4.0.1 [flutter flutter_web_plugins http google_maps_flutter]
- amplify_api 0.4.2 [amplify_api_plugin_interface amplify_core collection flutter meta plugin_platform_interface]
- amplify_auth_cognito 0.4.2 [flutter amplify_auth_plugin_interface amplify_core amplify_auth_cognito_android amplify_auth_cognito_ios collection plugin_platform_interface]
- amplify_datastore 0.4.2 [flutter amplify_datastore_plugin_interface amplify_core plugin_platform_interface meta collection async]
- amplify_flutter 0.4.2 [amplify_analytics_plugin_interface amplify_api_plugin_interface amplify_auth_plugin_interface amplify_core amplify_datastore_plugin_interface amplify_storage_plugin_interface collection flutter json_annotation meta plugin_platform_interface]
- amplify_storage_s3 0.4.2 [flutter amplify_storage_plugin_interface plugin_platform_interface amplify_storage_s3_android amplify_storage_s3_ios amplify_core]
- animated_splash_screen 1.2.0 [flutter page_transition]
- cupertino_icons 1.0.4
- encrypt 5.0.1 [args asn1lib clock collection crypto pointycastle]
- f_logs 2.0.0 [flutter sembast path_provider intl xxtea meta path stack_trace]
- flutter 0.0.0 [characters collection material_color_utilities meta typed_data vector_math sky_engine]
- flutter_credit_card 3.0.1 [flutter]
- flutter_native_splash 2.1.2+1 [args image js meta path xml yaml universal_io flutter flutter_web_plugins]
- flutter_signin_button 2.0.0 [flutter font_awesome_flutter]
- geolocator 8.2.0 [flutter geolocator_platform_interface geolocator_android geolocator_apple geolocator_web geolocator_windows]
- google_geocoding 0.2.0 [flutter http]
- google_maps_flutter 2.1.1 [flutter flutter_plugin_android_lifecycle google_maps_flutter_platform_interface]
- http 0.13.4 [async http_parser meta path]
- im_stepper 0.1.3 [flutter]
- image_picker 0.8.4+10 [flutter flutter_plugin_android_lifecycle image_picker_for_web image_picker_platform_interface]
- intl 0.17.0 [clock path]
- location 4.3.0 [flutter location_platform_interface location_web]
- material_floating_search_bar 0.3.7 [flutter meta]
- mockito 5.1.0 [analyzer build code_builder collection dart_style matcher meta path source_gen test_api]
- path 1.8.0
- path_provider 2.0.9 [flutter path_provider_android path_provider_ios path_provider_linux path_provider_macos path_provider_platform_interface path_provider_windows]
- permission_handler 9.2.0 [flutter meta permission_handler_android permission_handler_apple permission_handler_windows permission_handler_platform_interface]
- provider 6.0.2 [collection flutter nested]
- qr_code_scanner 0.5.2 [js flutter flutter_web_plugins]
- qr_flutter 4.0.0 [flutter qr]
- shared_preferences 2.0.13 [flutter shared_preferences_android shared_preferences_ios shared_preferences_linux shared_preferences_macos shared_preferences_platform_interface shared_preferences_web shared_preferences_windows]
- sqflite 2.0.2 [flutter sqflite_common path]
- tuple 2.0.0 [quiver]
- url_launcher 6.0.20 [flutter url_launcher_android url_launcher_ios url_launcher_linux url_launcher_macos url_launcher_platform_interface url_launcher_web url_launcher_windows]
- widget_arrows 0.2.0-nullsafety.0 [flutter]

transitive dependencies:
- _fe_analyzer_shared 31.0.0 [meta]
- amplify_analytics_plugin_interface 0.4.2 [amplify_core flutter meta]
- amplify_api_plugin_interface 0.4.2 [amplify_core collection flutter json_annotation meta]
- amplify_auth_cognito_android 0.4.2 [flutter]
- amplify_auth_cognito_ios 0.4.2 [amplify_core flutter]
- amplify_auth_plugin_interface 0.4.2 [flutter meta amplify_core]
- amplify_core 0.4.2 [flutter plugin_platform_interface collection date_time_format meta uuid]
- amplify_datastore_plugin_interface 0.4.2 [flutter meta collection amplify_core]
- amplify_storage_plugin_interface 0.4.2 [flutter meta amplify_core]
- amplify_storage_s3_android 0.4.2 [flutter]
- amplify_storage_s3_ios 0.4.2 [flutter]
- analyzer 2.8.0 [_fe_analyzer_shared cli_util collection convert crypto glob meta package_config path pub_semver source_span watcher yaml]
- archive 3.1.6 [crypto path]
- args 2.3.0
- asn1lib 1.1.0
- async 2.8.2 [collection meta]
- boolean_selector 2.1.0 [source_span string_scanner]
- build 2.2.1 [analyzer async convert crypto glob logging meta path]
- built_collection 5.1.1
- built_value 8.1.4 [built_collection collection fixnum meta]
- characters 1.2.0
- charcode 1.3.1
- cli_util 0.3.5 [meta path]
- clock 1.1.0
- code_builder 4.1.0 [built_collection built_value collection matcher meta]
- collection 1.15.0
- convert 3.0.1 [typed_data]
- cross_file 0.3.2 [flutter js meta]
- crypto 3.0.1 [collection typed_data]
- dart_style 2.2.1 [analyzer args path pub_semver source_span]
- date_time_format 2.0.1
- ffi 1.1.2
- file 6.1.2 [meta path]
- fixnum 1.0.0
- flutter_plugin_android_lifecycle 2.0.5 [flutter]
- flutter_web_plugins 0.0.0 [flutter js characters collection material_color_utilities meta typed_data vector_math]
- font_awesome_flutter 9.2.0 [flutter]
- geolocator_android 3.1.0 [flutter geolocator_platform_interface]
- geolocator_apple 2.1.1+1 [flutter geolocator_platform_interface]
- geolocator_platform_interface 4.0.3 [flutter plugin_platform_interface vector_math meta]
- geolocator_web 2.1.4 [flutter flutter_web_plugins geolocator_platform_interface]
- geolocator_windows 0.1.0 [flutter geolocator_platform_interface]
- glob 2.0.2 [async collection file path string_scanner]
- google_maps_flutter_platform_interface 2.1.4 [collection flutter meta plugin_platform_interface stream_transform]
- http_parser 4.0.0 [charcode collection source_span string_scanner typed_data]
- image 3.1.3 [archive meta xml]
- image_picker_for_web 2.1.4 [flutter flutter_web_plugins image_picker_platform_interface meta]
- image_picker_platform_interface 2.4.2 [flutter http meta plugin_platform_interface cross_file]
- js 0.6.3
- json_annotation 4.4.0 [meta]
- location_platform_interface 2.3.0 [flutter meta plugin_platform_interface]
- location_web 3.1.1 [flutter flutter_web_plugins http_parser js location_platform_interface meta]
- logging 1.0.2
- matcher 0.12.11 [stack_trace]
- material_color_utilities 0.1.3
- meta 1.7.0
- nested 1.0.0 [flutter]
- package_config 2.0.2 [path]
- page_transition 2.0.5 [flutter]
- path_provider_android 2.0.12 [flutter path_provider_platform_interface]
- path_provider_ios 2.0.8 [flutter path_provider_platform_interface]
- path_provider_linux 2.1.5 [ffi flutter path path_provider_platform_interface xdg_directories]
- path_provider_macos 2.0.5 [flutter path_provider_platform_interface]
- path_provider_platform_interface 2.0.3 [flutter platform plugin_platform_interface]
- path_provider_windows 2.0.5 [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.3 [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]
- petitparser 4.4.0 [meta]
- platform 3.1.0
- plugin_platform_interface 2.1.2 [meta]
- pointycastle 3.5.2 [collection convert js]
- process 4.2.4 [file path platform]
- pub_semver 2.1.1 [collection meta]
- qr 2.1.0 [meta]
- quiver 3.0.1+1 [matcher]
- sembast 3.2.0 [meta path synchronized]
- shared_preferences_android 2.0.11 [flutter shared_preferences_platform_interface]
- shared_preferences_ios 2.1.0 [flutter shared_preferences_platform_interface]
- shared_preferences_linux 2.1.0 [file flutter path path_provider_linux path_provider_platform_interface shared_preferences_platform_interface]
- shared_preferences_macos 2.0.3 [flutter shared_preferences_platform_interface]
- shared_preferences_platform_interface 2.0.0 [flutter]
- shared_preferences_web 2.0.3 [flutter flutter_web_plugins shared_preferences_platform_interface]
- shared_preferences_windows 2.1.0 [file flutter path path_provider_platform_interface path_provider_windows shared_preferences_platform_interface]
- sky_engine 0.0.99
- source_gen 1.2.1 [analyzer async build dart_style glob meta path source_span yaml]
- source_span 1.8.1 [collection path term_glyph]
- sqflite_common 2.2.0 [synchronized path meta]
- stack_trace 1.10.0 [path]
- stream_channel 2.1.0 [async]
- stream_transform 2.0.0
- string_scanner 1.1.0 [charcode source_span]
- synchronized 3.0.0
- term_glyph 1.2.0
- test_api 0.4.8 [async boolean_selector collection meta source_span stack_trace stream_channel string_scanner term_glyph matcher]
- typed_data 1.3.0 [collection]
- universal_io 2.0.4 [collection crypto meta typed_data]
- url_launcher_android 6.0.15 [flutter url_launcher_platform_interface]
- url_launcher_ios 6.0.15 [flutter url_launcher_platform_interface]
- url_launcher_linux 3.0.0 [flutter url_launcher_platform_interface]
- url_launcher_macos 3.0.0 [flutter url_launcher_platform_interface]
- url_launcher_platform_interface 2.0.5 [flutter plugin_platform_interface]
- url_launcher_web 2.0.9 [flutter flutter_web_plugins url_launcher_platform_interface]
- url_launcher_windows 3.0.0 [flutter url_launcher_platform_interface]
- uuid 3.0.5 [crypto]
- vector_math 2.1.1
- watcher 1.0.1 [async path]
- win32 2.4.1 [ffi]
- xdg_directories 0.2.0+1 [meta path process]
- xml 5.3.1 [collection meta petitparser]
- xxtea 2.1.0
- yaml 3.1.0 [collection source_span string_scanner]

Device

iPhone 13

OS

iOS 15.2.0

CLI Version

7.6.26

Additional Context

https://github.com/aws-amplify/amplify-js/issues/9318 https://github.com/aws-amplify/amplify-android/issues/2258 https://github.com/aws-amplify/amplify-swift/issues/2708

haverchuck commented 2 years ago

@irisk29 This is not currently supported, due to a Cognito limitation that device tracking functionality can only be used in tandem with the USER_SRP_AUTH flow.

irisk29 commented 2 years ago

@haverchuck in amplifyconfiguration under Auth I have this set: "authenticationFlowType": "USER_SRP_AUTH" Is this not enough?

If not, are you aware of any other solution that I can use?

haverchuck commented 2 years ago

@irisk29 If you want to do device tracking, I believe you would have to use the signIn APIs to login directly to Cognito User Pools instead of using the Hosted UI OAuth flow. We have a prebuilt UI component for these called the Authenticator. However, in either case you would not be able to use device tracking with social provider logins.

Please note the Authenticator also can hook in to hosted UI for social provider logins if these are part of your config, but to use device tracking you will need to login directly with Cognito User Pools

rasmus-rudling commented 1 year ago

If I understand it correctly, the rememberDevice will only work if the users sign in using username and password? How would you in that case refresh the idToken and let Amplify know about the fresh idToken? Isn't social sign ins a big part of Amplify Auth? Maybe I'm misunderstanding exactly what rememberDevice does!