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

Delete operation not working in android but working in IOS #2613

Closed PriyaranjanEuphotic closed 1 year ago

PriyaranjanEuphotic commented 1 year ago

Description

Future removeId({ required String id, }) async { CognitoAuthSession session = await Amplify.Auth.fetchAuthSession( options: CognitoSessionOptions(getAWSCredentials: true)) as CognitoAuthSession;

Map<String, String> header = {
  "Authorization": session.userPoolTokens!.idToken,
};

RestOptions options = RestOptions(
  apiName: "path",
  path: "/path/$id",
  headers: header,
);

RestOperation operation = Amplify.API.delete(restOptions: options);
RestResponse response = await operation.response;

Error: - {"message":"Authorization header requires 'Credential' parameter. Authorization header requires 'Signature' parameter. Authorization header requires 'SignedHeaders' parameter. Authorization header requires existence of either a 'X-Amz-Date' or a 'Date' header. Authorization=eyJraWQiOiJreDVUUTBFbXk3Vlwvd0E5akpvQ0tcL3hrSjJOSlIwYmRPZlFNc0daR1o4VUU9IiwiYWxnIjoiUlMyNTYifQ.eyJzdWIiOiJkMDY3MTU5Yy01MjJiLTRjYjYtOTU2Yi0zNTg3MDFmNDUyNmYiLCJlbWFpbF92ZXJpZmllZCI6dHJ1ZSwiaXNzIjoiaHR0cHM6XC9cL2NvZ25pdG8taWRwLmFwLXNvdXRoLTEuYW1hem9uYXdzLmNvbVwvYXAtc291dGgtMV9LQ0x1MUpPREgiLCJjb2duaXRvOnVzZXJuYW1lIjoiZDA2NzE1OWMtNTIyYi00Y2I2LTk1NmItMzU4NzAxZjQ1MjZmIiwiYXVkIjoiMW5hdnZra2pnYmUzOGNxNGZraWEyYTVlOXIiLCJldmVudF9pZCI6IjBlYjlkZDQ5LTcxNmEtNDY3YS04NThkLTZhNjQxYjA4MTQ0ZSIsInRva2VuX3VzZSI6ImlkIiwiYXV0aF90aW1lIjoxNjc1MTUyMTc0LCJuYW1lIjoiUHJpeWFyYW5qYW4iLCJleHAiOjE2NzUxNTU3NzQsImlhdCI6MTY3NTE1MjE3NCwiZW1haWwiOiJwcml5YXJhbmphbkBldXBob3RpYy5pbyJ9.f4Reb6o637goGmSlxXm73wCMM01mR1vDCfPvdsbCBFTWhy98uvVs3_aM3v6O8IiFvPigB3yDzR8X9C7sn5fshfdUndT0CnrBUO41ZT59bUc9cIQpHVeBRNTLcoAn8MHIlwJptm33l1EKr3nDAKnnmxDLok6kLAz5Yy9KIdTsMveUebSD980QwhPA7AwOAHh61WQWkyQ5hm_uy3bbsXr7JD_JMsxme8Y66DJ-QwOfIUesJkV8XcjgERgdW1sn2V0QFcwdD17xn-4nUcpBVeMOw9gYYN9iiXb38voqR-jih6_j2NENZ18ZWAChF0iIe8rWV6J0yKZ1iiokJ8BBJPxgRA"}

While I am trying to perform above operation, I'm getting following error.

I am not getting any error with get, post and put request.

Categories

Steps to Reproduce

No response

Screenshots

No response

Platforms

Android Device/Emulator API Level

No response

Environment

[✓] Flutter (Channel stable, 3.7.0, on macOS 12.5 21G72 darwin-arm64, locale en-IN)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
[✓] Xcode - develop for iOS and macOS (Xcode 14.2)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.3)
[✓] VS Code (version 1.74.2)
[✓] Connected device (3 available)
[✓] HTTP Host Availability

 Doctor found issues in 0 category.

Dependencies

dependencies:
- amplify_api 0.6.12 [amplify_api_android amplify_api_ios amplify_core amplify_flutter aws_common collection flutter meta plugin_platform_interface]
- amplify_auth_cognito 0.6.12 [amplify_auth_cognito_android amplify_auth_cognito_ios amplify_core aws_common collection flutter meta plugin_platform_interface]
- amplify_flutter 0.6.12 [amplify_core amplify_datastore_plugin_interface amplify_flutter_android amplify_flutter_ios aws_common collection flutter meta plugin_platform_interface]
- auto_route 5.0.4 [flutter path collection meta]
- aws_iot 1.0.0+1 [convert crypto flutter mqtt_client typed_data sigv4]
- aws_iot_api 2.0.0 [shared_aws_api]
- badges 2.0.3 [flutter]
- cached_network_image 3.2.3 [flutter flutter_cache_manager octo_image cached_network_image_platform_interface cached_network_image_web]
- circular_menu 2.0.1 [flutter]
- collection 1.17.0
- cupertino_icons 1.0.5
- device_info_plus 8.0.0 [device_info_plus_platform_interface ffi file flutter flutter_web_plugins meta win32]
- device_preview 1.1.0 [flutter flutter_localizations provider device_frame freezed_annotation json_annotation shared_preferences collection]
- firebase_core 2.4.1 [firebase_core_platform_interface firebase_core_web flutter meta]
- firebase_messaging 14.2.1 [firebase_core firebase_core_platform_interface firebase_messaging_platform_interface firebase_messaging_web flutter meta]
- flutter 0.0.0 [characters collection js material_color_utilities meta vector_math sky_engine]
- flutter_form_builder 7.7.0 [flutter intl collection]
- flutter_local_notifications 13.0.0 [clock flutter flutter_local_notifications_linux flutter_local_notifications_platform_interface timezone]
- flutter_localizations 0.0.0 [flutter intl characters clock collection js material_color_utilities meta path vector_math]
- flutter_native_splash 2.2.16 [args flutter flutter_web_plugins js html image meta path universal_io xml yaml]
- flutter_rating_bar 4.0.1 [flutter]
- flutter_riverpod 2.1.3 [collection flutter meta riverpod state_notifier]
- flutter_svg 1.1.6 [flutter meta path_drawing vector_math xml]
- fluttertoast 8.1.2 [flutter flutter_web_plugins]
- form_builder_validators 8.4.0 [flutter flutter_localizations intl]
- fraction 4.1.4
- gap 2.0.1 [flutter]
- hive_flutter 1.1.0 [flutter hive path_provider path]
- http 0.13.5 [async http_parser meta path]
- intl 0.17.0 [clock path]
- json_annotation 4.8.0 [meta]
- mobile_scanner 2.1.0 [flutter flutter_web_plugins js]
- multiple_result 4.0.0 [meta]
- responsive_framework 0.2.0 [flutter collection]
- share_plus 6.3.0 [cross_file meta mime flutter flutter_web_plugins share_plus_platform_interface file url_launcher_web url_launcher_windows url_launcher_linux url_launcher_platform_interface ffi win32]
- shimmer 2.0.0 [flutter]
- sigv4 5.0.1-nullsafety.1 [crypto http convert dio meta]
- syncfusion_flutter_sliders 20.4.44 [flutter intl syncfusion_flutter_core]
- url_launcher 6.1.8 [flutter url_launcher_android url_launcher_ios url_launcher_linux url_launcher_macos url_launcher_platform_interface url_launcher_web url_launcher_windows]

transitive dependencies:
- _flutterfire_internals 1.0.12 [collection firebase_core firebase_core_platform_interface flutter meta]
- amplify_api_android 0.6.12 [flutter]
- amplify_api_ios 0.6.12 [amplify_core flutter]
- amplify_auth_cognito_android 0.6.12 [flutter]
- amplify_auth_cognito_ios 0.6.12 [amplify_core flutter]
- amplify_core 0.6.12 [aws_common collection flutter intl json_annotation meta plugin_platform_interface uuid]
- amplify_datastore_plugin_interface 0.6.12 [amplify_core collection flutter meta]
- amplify_flutter_android 0.6.12 [flutter]
- amplify_flutter_ios 0.6.12 [amplify_core flutter]
- archive 3.3.5 [crypto path pointycastle]
- args 2.3.2
- async 2.10.0 [collection meta]
- aws_common 0.1.1 [async collection http meta stream_transform uuid]
- boolean_selector 2.1.1 [source_span string_scanner]
- cached_network_image_platform_interface 2.0.0 [flutter flutter_cache_manager]
- cached_network_image_web 1.0.2 [flutter flutter_cache_manager cached_network_image_platform_interface]
- characters 1.2.1
- clock 1.1.1
- convert 3.1.1 [typed_data]
- cross_file 0.3.3+2 [js meta]
- crypto 3.0.2 [typed_data]
- csslib 0.17.2 [source_span]
- dbus 0.7.8 [args ffi meta xml]
- device_frame 1.1.0 [freezed_annotation flutter]
- device_info_plus_platform_interface 7.0.0 [flutter meta plugin_platform_interface]
- dio 4.0.6 [http_parser path]
- event_bus 2.0.0
- fake_async 1.3.1 [clock collection]
- ffi 2.0.1
- file 6.1.4 [meta path]
- firebase_core_platform_interface 4.5.2 [collection flutter flutter_test meta plugin_platform_interface]
- firebase_core_web 2.1.0 [firebase_core_platform_interface flutter flutter_web_plugins js meta]
- firebase_messaging_platform_interface 4.2.10 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface]
- firebase_messaging_web 3.2.11 [_flutterfire_internals firebase_core firebase_core_web firebase_messaging_platform_interface flutter flutter_web_plugins js meta]
- flutter_blurhash 0.7.0 [flutter]
- flutter_cache_manager 3.3.0 [clock collection file flutter http path path_provider pedantic rxdart sqflite uuid]
- flutter_local_notifications_linux 3.0.0 [dbus ffi flutter flutter_local_notifications_platform_interface path xdg_directories]
- flutter_local_notifications_platform_interface 6.0.0 [flutter plugin_platform_interface]
- flutter_test 0.0.0 [flutter test_api path fake_async clock stack_trace vector_math async boolean_selector characters collection js 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]
- freezed_annotation 2.2.0 [collection json_annotation meta]
- hive 2.2.3 [meta crypto]
- html 0.15.1 [csslib source_span]
- http_parser 4.0.2 [collection source_span string_scanner typed_data]
- image 3.3.0 [archive meta xml]
- js 0.6.5 [meta]
- matcher 0.12.13 [meta stack_trace]
- material_color_utilities 0.2.0
- meta 1.8.0
- mime 1.0.4
- mqtt_client 9.7.4 [typed_data event_bus path crypto meta]
- nested 1.0.0 [flutter]
- octo_image 1.0.2 [flutter flutter_blurhash]
- path 1.8.2
- path_drawing 1.0.1 [vector_math meta path_parsing flutter]
- path_parsing 1.0.1 [vector_math meta]
- path_provider 2.0.12 [flutter path_provider_android path_provider_foundation path_provider_linux path_provider_platform_interface path_provider_windows]
- path_provider_android 2.0.22 [flutter path_provider_platform_interface]
- path_provider_foundation 2.1.1 [flutter path_provider_platform_interface]
- path_provider_linux 2.1.7 [ffi flutter path path_provider_platform_interface xdg_directories]
- path_provider_platform_interface 2.0.5 [flutter platform plugin_platform_interface]
- path_provider_windows 2.1.3 [ffi flutter path path_provider_platform_interface win32]
- pedantic 1.11.1
- petitparser 5.1.0 [meta]
- platform 3.1.0
- plugin_platform_interface 2.1.3 [meta]
- pointycastle 3.6.2 [collection convert js]
- process 4.2.4 [file path platform]
- provider 6.0.5 [collection flutter nested]
- riverpod 2.1.3 [collection meta stack_trace state_notifier]
- rxdart 0.27.7
- share_plus_platform_interface 3.2.0 [cross_file flutter meta mime plugin_platform_interface path_provider uuid]
- shared_aws_api 2.0.0 [crypto http meta xml intl uuid collection]
- shared_preferences 2.0.17 [flutter shared_preferences_android shared_preferences_foundation shared_preferences_linux shared_preferences_platform_interface shared_preferences_web shared_preferences_windows]
- shared_preferences_android 2.0.15 [flutter shared_preferences_platform_interface]
- shared_preferences_foundation 2.1.2 [flutter shared_preferences_platform_interface]
- shared_preferences_linux 2.1.3 [file flutter path path_provider_linux path_provider_platform_interface shared_preferences_platform_interface]
- shared_preferences_platform_interface 2.1.0 [flutter plugin_platform_interface]
- shared_preferences_web 2.0.4 [flutter flutter_web_plugins shared_preferences_platform_interface]
- shared_preferences_windows 2.1.3 [file flutter path path_provider_platform_interface path_provider_windows shared_preferences_platform_interface]
- sky_engine 0.0.99
- source_span 1.9.1 [collection path term_glyph]
- sqflite 2.2.4+1 [flutter sqflite_common path]
- sqflite_common 2.4.2+2 [synchronized path meta]
- stack_trace 1.11.0 [path]
- state_notifier 0.7.2+1 [meta]
- stream_channel 2.1.1 [async]
- stream_transform 2.1.0
- string_scanner 1.2.0 [source_span]
- synchronized 3.0.1
- term_glyph 1.2.1
- test_api 0.4.16 [async boolean_selector collection meta source_span stack_trace stream_channel string_scanner term_glyph matcher]
- timezone 0.9.1 [path]
- typed_data 1.3.1 [collection]
- universal_io 2.0.4 [collection crypto meta typed_data]
- url_launcher_android 6.0.23 [flutter url_launcher_platform_interface]
- url_launcher_ios 6.0.18 [flutter url_launcher_platform_interface]
- url_launcher_linux 3.0.2 [flutter url_launcher_platform_interface]
- url_launcher_macos 3.0.2 [flutter url_launcher_platform_interface]
- url_launcher_platform_interface 2.1.1 [flutter plugin_platform_interface]
- url_launcher_web 2.0.14 [flutter flutter_web_plugins url_launcher_platform_interface]
- url_launcher_windows 3.0.3 [flutter url_launcher_platform_interface]
- uuid 3.0.6 [crypto]
- vector_math 2.1.4
- win32 3.1.3 [ffi]
- xdg_directories 0.2.0+3 [meta path process]
- xml 6.2.2 [collection meta petitparser]
- yaml 3.1.1 [collection source_span string_scanner]

Device

Pixel 3a

OS

Android 12

Deployment Method

Amplify CLI + Custom Pipeline

CLI Version

No response

Additional Context

No response

Amplify Config

"UserAgent": "aws-amplify-cli/2.0",
"Version": "1.0",
fjnoyp commented 1 year ago

Hi @PriyaranjanEuphotic thanks for posting this issue.

Are you able to verify that the delete request is actually succeeding on both platforms? Are all other requests succeeding on both platforms or are they just completing without throwing any errors?

PriyaranjanEuphotic commented 1 year ago

ya I tried delete request in both devices but, getting success in ios but failed in android. other requests are working fine like post, put, get, etc.

fjnoyp commented 1 year ago

Hi @PriyaranjanEuphotic what instructions did you follow to setup the auth of your REST API?

Can you provide your amplify config file with the sensitive keys redacted?

This extensive issue here might be related depending on if your setup is similar: https://github.com/aws-amplify/amplify-flutter/issues/1539

ragingsquirrel3 commented 1 year ago

@PriyaranjanEuphotic another question for you: When you say HTTP GET, POST working, is your code that sends those requests using the same logic as example with DELETE to supply the HTTP header with the ID token? The error message seems to indicate some server-side error with IAM authentication, which it appears you are trying to override with Cognito user pools auth, so I wasn't sure if working methods (GET, POST) were using IAM.

ragingsquirrel3 commented 1 year ago

Without a little more info about use case, here's what I was able to determine about REST API in this android use case: Reported error is expected behavior if trying to custom authorize a request on backend/amplify config that otherwise use IAM (e.g. sign the request with AWS credentials, default auth mode for REST API). That's because the Android's IAM request decorator does not short-circuit if there is already an "Authorization" parameter set, resulting in an incorrectly signed request which throws a server-side error. Note that in the dev preview version and iOS, this is a little difference that the client won't sign a request with an "Authorization" header set. You could try renaming the header something else so it doesn't interfere with signing like "My-Authorization". If you don't want the client to sign the request at all, you could setup a different auth mode. Then, there is some work to make the backend accept new Auth schema either way as the CLI only supports IAM mode by default.

Let me know if this answers your question about the error you got.

PriyaranjanEuphotic commented 1 year ago

Hi, I tried with "amplify_api: ^0.5.1" everything working fine. but with version 0.6.12 delete request is not working

fjnoyp commented 1 year ago

Hi @PriyaranjanEuphotic thanks for that information, in order to better help you here can you please answer the above questions though. We are guessing at what you might have done and proposing solutions based on that.

1) How are you authorizing requests, are you using the default authorization rules with IAM authorization? Or are you using cognito user pools / api key / oidc / custom http request headers?

https://docs.amplify.aws/lib/restapi/authz/q/platform/flutter/

2) Is the code that sends HTTP GET, POST requests using the same logic as DELETE? Is the supplied HTTP header with ID token the same?

Jordan-Nelson commented 1 year ago

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

Jordan-Nelson commented 1 year ago

@PriyaranjanEuphotic - I an going to close this out since we have not heard back. If you are still facing this issue, please provide the info request above.