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

Signature needs region when using AppSync custom domains #28

Open
danielsharvey opened this issue Nov 12, 2023 · 1 comment
Open

Signature needs region when using AppSync custom domains #28

danielsharvey opened this issue Nov 12, 2023 · 1 comment

Comments

@danielsharvey
Copy link

When using AppSync custom domains (https://docs.aws.amazon.com/appsync/latest/devguide/custom-domain-name.html), the produced signature does not contain the region (cannot be inferred from URL) and so the auth fails.

I have tested a fix by inserting region: "ap-southeast-2", after line 34:

return {
host,
method: "POST",
path,
service: "appsync",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
query: rawQuery,
variables,
}),
};

Of note, the library does not report this error well. I have tested at fix by inserting the following in the the result.on("end", ... processing (line 21 below):

if (result.statusCode !== 200) {
  // reject(new Error(`Error: Status Code ${result.statusCode}`));
  console.log('STATUS CODE', result.statusCode);
  console.log('STATUS RESPONSE', rawResponseBody);
}

result.on("end", () => {
try {
// JSON parse the response body
const body = JSON.parse(rawResponseBody);
// Reject if no data
if (!body.data) {
reject(Error(rawResponseBody));
}
// Resolve with just that data
resolve(body.data);
} catch (e) {
// Throw the full body if it isn't JSON (usually this is where a GraphQL server is responding with e.g. an
// error page instead of a properly formatted GraphQL error.)
reject(Error(rawResponseBody));
}
});

I can submit a PR soon unless someone beats me to it.

@danielsharvey
Copy link
Author

This is probably the same / related to #24.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant