arnemolland / sigv4

Dart library for signing AWS requests with Signature Version 4
MIT License
17 stars 23 forks source link

Expected a value of type 'String', but got one of type 'bool' #26

Closed BartusZak closed 3 years ago

BartusZak commented 3 years ago

Hey @arnemolland,

I have already reported that issue before after you updated the package to higher version (https://github.com/arnemolland/sigv4/issues/19#issuecomment-780451709).

import 'package:sigv4/sigv4.dart';

this.client =  Sigv4Client(
              keyId: keyId,
              accessKey: accessKey,
              region: region,
              serviceName: serviceName,
            );

 final request = client.request(
        url,
        headers: {
          HttpHeaders.contentTypeHeader: 'application/json',
        },
      );

//Exception Expected a value of type 'String', but got one of type 'bool'
sigv4: ^5.0.0-nullsafety.0
flutter doctor ``` Doctor summary (to see all details, run flutter doctor -v): [√] Flutter (Channel stable, 2.0.3, on Microsoft Windows [Version 10.0.19042.867], locale en-US) [√] Android toolchain - develop for Android devices (Android SDK version 30.0.3) [√] Chrome - develop for the web [√] Android Studio (version 4.1.0) [√] VS Code (version 1.54.3) [√] Connected device (2 available) • No issues found! ```
BartusZak commented 3 years ago

I forked your project and tried to run example with existing credentials and there is a result:

Exception ``` Error: Expected a value of type 'String', but got one of type 'bool' at Object.throw_ [as throw] (http://localhost:65216/dart_sdk.js:5334:11) at Object.castError (http://localhost:65216/dart_sdk.js:5305:15) at Object.cast [as as] (http://localhost:65216/dart_sdk.js:5621:17) at dart.LegacyType.new.as (http://localhost:65216/dart_sdk.js:7219:60) at http://localhost:65216/dart_sdk.js:21823:26 at IdentityMap.new.forEach (http://localhost:65216/dart_sdk.js:26139:11) at CastMap.new.forEach (http://localhost:65216/dart_sdk.js:21822:33) at CustomHashMap.new.addAll (http://localhost:65216/dart_sdk.js:26751:24) at client.Sigv4Client.new.request (http://localhost:65216/packages/sigv4/src/client.dart.lib.js:160:31) at main$ (http://localhost:65216/packages/sigv4/main.dart.lib.js:38:26) at main (http://localhost:65216/web_entrypoint.dart.lib.js:46:29) at main.next () at http://localhost:65216/dart_sdk.js:39032:33 at _RootZone.runUnary (http://localhost:65216/dart_sdk.js:38889:58) at _FutureListener.thenAwait.handleValue (http://localhost:65216/dart_sdk.js:33875:29) at handleValueCallback (http://localhost:65216/dart_sdk.js:34435:49) at Function._propagateToListeners (http://localhost:65216/dart_sdk.js:34473:17) at _Future.new.[_completeWithValue] (http://localhost:65216/dart_sdk.js:34315:23) at http://localhost:65216/dart_sdk.js:33526:46 at _RootZone.runUnary (http://localhost:65216/dart_sdk.js:38889:58) at _FutureListener.then.handleValue (http://localhost:65216/dart_sdk.js:33875:29) at handleValueCallback (http://localhost:65216/dart_sdk.js:34435:49) at Function._propagateToListeners (http://localhost:65216/dart_sdk.js:34473:17) at _Future.new.[_completeWithValue] (http://localhost:65216/dart_sdk.js:34315:23) at async._AsyncCallbackEntry.new.callback (http://localhost:65216/dart_sdk.js:34338:35) at Object._microtaskLoop (http://localhost:65216/dart_sdk.js:39176:13) at _startMicrotaskLoop (http://localhost:65216/dart_sdk.js:39182:13) at http://localhost:65216/dart_sdk.js:34689:9 ```

client.dart line 202 image

BartusZak commented 3 years ago

https://github.com/arnemolland/sigv4/pull/28 does not throw an exception now, and I can build my project but the signature is calculated wrongly and it throws 400 Not Found when trying to access secured Amazon S3 Bucket.

Error ``` InvalidArgument x-amz-content-sha256 must be UNSIGNED-PAYLOAD, STREAMING-AWS4-HMAC-SHA256-PAYLOAD, or a valid sha256 value. x-amz-content-sha256 true HZSPKW786CJ42B0C up9dBY04lEKWAZvP0e246HpnSN4iOKn5n96RtQhpHeR+k0Ez6HLYL4rtrfeflr4XxIrHtw2PoEs= ```
BartusZak commented 3 years ago

Ok, I have figured out what is goin' on here :D

The problem started with: https://github.com/arnemolland/sigv4/commit/0ab927da5827a3ccb62998a5f9e0d74737316652