arnemolland / sigv4

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

Signature is wrong for Lex service #16

Closed primemb closed 4 years ago

primemb commented 4 years ago

I use this package to send post request to Lex service like this :

Sigv4Client client = Sigv4Client(
      keyId: kAccessKey,
      accessKey: kSecretKey,
      region: 'us-east-1',
      serviceName: 'lex',
    );

final request = client.request(
      'https://runtime.lex.us-east-1.amazonaws.com/bot/myBotName/alias/BETA/user/myUserid/text',
      method: 'POST',
      body: jsonEncode({"inputText": "hi"}),
    );

var response = await http.post(request.url,
        headers: request.headers, body: request.body);

print(request.url.toString());

but i get error from api :

{"message":"The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details."}

my bot work with postman but not with this package i also noticed the "X-Amz-Content-Sha256" is different on postman and package on postman X-Amz-Content-Sha256 value is: "beaead3198f7da1e70d03ab969765e0821b24fc913697e929e726aeaebf0eba3"

and on this package value is : "ee9ef87bd5a357cff93b1d83d1e8a1b47fb3fa2e94251711c6a30250119e6369"

on both body value is :

{"inputText": "hi"}

when i change the code like this :

var headers = client.signedHeaders(
      kFullApiUrl,
      method: 'POST',
      signPayload: false,
    );
    var response = await http.post(
      kFullApiUrl,
      headers: headers,
    );
    print(response.body.toString());

i got this message : {"message":"1 validation error detected: Value at 'inputText' failed to satisfy constraint: Member must not be null"} so i think it's something wrong in payload hash.

mightbeshreyazyllu commented 4 years ago

@primemb , hey, were you able to resolve this error? Can you please share what you did to fix it?

primemb commented 4 years ago

@mightbeshreyazyllu hey, you can check here https://stackoverflow.com/questions/62486973/amazon-lex-authorization-with-flutter

arnemolland commented 4 years ago

Hi! Sorry for the late response. I'm not actively maintaining this anymore. If there's a fix and you'd like to continue using the library, you're welcome to open a PR. If not, I recommend checking out this repo.