Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The request signature we calculated does not match the signature you provided. #639

Closed
castrors opened this issue May 15, 2020 · 3 comments
Labels
⌛ reproduction needed Issue is subtle and requires a true accessible reproduction to debug 👵 outdated Outdated and will be closed soon unless reproduced on the latest beta

Comments

@castrors
Copy link

Describe the bug
I'm using AWS Appsync and then, when I try to make a request with the same parameters via http, it goes with success.
But when I try with graphql-flutter, I'm getting this error:

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.

The Canonical String for this request should have been
'POST
/graphql

accept:application/json
content-type:application/graphql; charset=utf-8
host:www.host.com
x-amz-date:0000000000000
accept;content-type;host;x-amz-date
AAAAA'

The String-to-Sign should have been
'AWS4-HMAC-SHA256
0000000000000
1111111/eu-west-1/appsync/aws4_request
BBBBB'

To Reproduce
This is my creation of the link using graphql-flutter:

import 'package:amazon_cognito_identity_dart_2/sig_v4.dart';

    final awsSigV4Client = AwsSigV4Client(
        credentials.accessKeyId, credentials.secretAccessKey, endpoint,
        serviceName: 'appsync',
        sessionToken: credentials.sessionToken,
        region: 'eu-west-1');

    final signedRequest = SigV4Request(awsSigV4Client,
        method: 'POST',
        path: '/graphql',
        headers: Map<String, String>.from(
            {'Content-Type': 'application/graphql; charset=utf-8'}),
        body: Map<String, String>.from({'query': query}));

    final CustomAuthLink authLink =
        CustomAuthLink(getHeaders: () => signedRequest.headers);

    return authLink.concat(httpLink);

Steps to reproduce the behavior:

  1. Just consume the AuthLink in the flutter app.

Expected behavior
This goes well when I'm using http.Request:

import 'package:amazon_cognito_identity_dart_2/sig_v4.dart';

    final awsSigV4Client = AwsSigV4Client(
        credentials.accessKeyId, credentials.secretAccessKey, endpointStaging,
        serviceName: 'appsync',
        sessionToken: credentials.sessionToken,
        region: 'eu-west-1');

    final signedRequest = SigV4Request(awsSigV4Client,
        method: 'POST',
        path: '/graphql',
        headers: Map<String, String>.from(
            {'Content-Type': 'application/graphql; charset=utf-8'}),
        body:
            Map<String, String>.from({'query': query}));

    http.Response response;
    try {
      response = await http.post(signedRequest.url,
          headers: signedRequest.headers, body: signedRequest.body);
    } catch (e) {
      print(e);
    }
    print(response.body);

Desktop (please complete the following information):

  • OS: macOS Catalina
  • Version 10.15.4

Smartphone (please complete the following information):

  • Device: android-x86 emulator
  • OS: Android
  • Version 10 (api 29)
@micimize
Copy link
Collaborator

Are you sure the only thing SigV4Request changes are the headers? Try

      response = await http.post(endpoint,
          headers: signedRequest.headers, body: {'query': query});

Other than that, try using content-type (lowercased), since the default is lowercased: https://github.com/zino-app/graphql-flutter/blob/eec7d2c5e8d753f7d2d62b2964cb61730caeae42/packages/graphql/lib/src/link/http/fallback_http_config.dart#L14

You can try something like #88 to debug as well

@2coo
Copy link

2coo commented Jun 29, 2020

@castrors Did you fix that? I have faced the problem too like yours

@micimize micimize added 👵 outdated Outdated and will be closed soon unless reproduced on the latest beta ⌛ reproduction needed Issue is subtle and requires a true accessible reproduction to debug labels Oct 7, 2020
@micimize
Copy link
Collaborator

micimize commented Oct 7, 2020

This is outdated / likely solved by us using gql_links in 4.0.0-beta.1 (#648). Please test there and have a look at appsync support section and related issues https://github.com/zino-app/graphql-flutter/tree/beta/packages/graphql#aws-appsync-support

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⌛ reproduction needed Issue is subtle and requires a true accessible reproduction to debug 👵 outdated Outdated and will be closed soon unless reproduced on the latest beta
Projects
None yet
Development

No branches or pull requests

3 participants