AppSync HTTP Resolver IAM Authorization Error - javascript

I am trying to use http resolvers with AWS AppSync so that we can support using graphQL and our REST APIs simultaneously. I got the AppSync http resolver working when the API Gateway did not have any authorization setup on it. However, I've now locked down the gateway with IAM and I am trying to call it with the http resolver.
Using Axios, I am able to call the API Gateway with and I get a good 200 response with these params.
Request Params
{
"body": "{\"id\":1234}",
"data": "{\"id\":1234}",
"headers": {
"Content-Type": "application/json; charset=UTF-8",
"x-amz-date": "20190209T101242Z",
"X-Amz-Security-Token": "AgoGb3JpZ2luEF4aCXVzLWVhc3QtMSKAAh9+SISFQH3bbHNLD47h5yCUsPmQhQ4Td74A1HmI/2jSu/Mg8mvK5IiMAMAMXokFQF8hZfzqsjfNWs+GcYkDRqhJbk7uaEaZFpjn5urgDAKVP/m5gywvnLnMWUXSOxTKe0kX+wTwHgnrV1wKR4+Fo97ykZPDasOPddw7HzSr9i2xKlKWEFB5iliZ08zvvA1OKUQ9gNdv6i+Cfwph/XGt0J7xvFtuYfOyZ5QRlyzggjS9cYbdaQ05A5vd+vAuDsdM7WXrU4OFN1ykRyw29VJU6eGFZTmBDX1AH7qI44ggjvwPOVUC/syAktuHgqqrADjleGdkRj0jZ+VoCybxAQYJEAQqpgUIcxAAGgw0OTc5OTY0NTMyNDgiDM9ufuhpC5ebbAUHHiqDBQ8P5DRX/leNqZEVIfcGahfFH6QfK9GZYDyW7iAVxHTEAL0ebMKi4Xo+vfatiISGgbTJuSB/csXvECTFkkuU1TNK21knO/WD5dWIIcKTSdQjZITMMtvTWk5JQWCFPrJ6ya6WENME3aYhfxXdCMuyL0EyFhx7A2J+GfukovfLRIU/CJl6GsyxSz0twNdBB71m7izPQ3rjN0ihNNayLWAfLhcU93Zq38BSavIesLYvqCpSYFH0fXrzhYaS+PRgKpvhgyR0r495OIIJfmSrMUZ2JZ/ct6YXanZCbEcFEwk91KPQDuG/NZhZcLpSPafU/HqkvaZ6gHSUpAR3jAi6XpLpaXHKS0vQnWV1ORnuIS/j9piDKe3HD42PsII9vgB69fZJK7wHImrqWwo9iKgHpiAYpJhs9K7lcznZ440NpjcA7VMBGBrvpFnLLv/VhTLVsYdNAeVfXMBshhEVsFVHvQstE/PHVvPTNMbk1eQwObKpQ/nprABPc4xWSKeF8w9TggwBrxemkDv+P0LhWqGso6WRssLH3GoKRE9znEawhvlxIbtDGJI38/j++zRTcreuduwbD29t+1pEk/5KJAnyxcQZmzTPlPTCA/TgRkeCEcOn7Xx/OZnG5137yK65xvHb2n1tPJsIDOlsD0AFP6me21sNkl5R4me746CR3ki0XUdIh4hPocKvlW+g32uWGBd6PMe+YwrCq8mD0NMxK3kgNMBtzX5IAyw51VTOIr01xCWrSegRbBtflYRtyHee2js3gu9N3ZfGHX13MDwvZi1WCfTDx3eP6wuPM4qcnJF/WBbkRU16PH8/Agkgxt5fQ4yaOOPv38GD1TRkGvWyshE2DJCilw27Qm8wms/64gU=",
"Authorization": "AWS4-HMAC-SHA256 Credential=ASIAXH4XG2WACM4YOUAC/20190209/us-east-1/execute-api/aws4_request, SignedHeaders=content-type;host;x-amz-date;x-amz-security-token, Signature=3b72f69aa94fe41026a7d8806cccfe50dd24b247df6681065435f7eba135d02e"
},
"method": "POST",
"path": "/Prod/test",
"url": "https://q1gyu9a0he.execute-api.us-east-1.amazonaws.com/Prod/test"
}
Response
{
"data": "Hello from Lambda!",
"status": 200,
"statusText": "OK",
"headers": {
"content-type": "application/json"
},
"config": {
"transformRequest": {},
"transformResponse": {},
"timeout": 0,
"xsrfCookieName": "XSRF-TOKEN",
"xsrfHeaderName": "X-XSRF-TOKEN",
"maxContentLength": -1,
"headers": {
"Accept": "application/json, text/plain, */*",
"Content-Type": "application/json; charset=UTF-8",
"x-amz-date": "20190209T101418Z",
"X-Amz-Security-Token": "AgoGb3JpZ2luEF4aCXVzLWVhc3QtMSKAAoEkajE677gfDz3UMEhI27lvIHgikCQIVivGmUBKwcIjfz+JH9z4ILd/HBp2i/fFwtOjUNpo0fFnJeN73QkY18BRdtuTwtbBmS0B+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jEAv8uguEoF9t4F4/3gt0g/0WAU1wX5kNGfpphpmeE6Do0rPCdlW3JDqNiZ7arsrAFgRSIw+s/64gU=",
"Authorization": "AWS4-HMAC-SHA256 Credential=ASIAXH4XG2WAC2MDEECX/20190209/us-east-1/execute-api/aws4_request, SignedHeaders=content-type;host;x-amz-date;x-amz-security-token, Signature=664af118dadc082a7fa72a7e51266c2e42fcd3a4a83813032087898490a3eeca"
},
"method": "post",
"body": "{\"id\":1234}",
"data": "{\"id\":1234}",
"path": "/Prod/test",
"url": "https://q1gyu9a0he.execute-api.us-east-1.amazonaws.com/Prod/test"
},
"request": {}
}
Using AppSync with the following http resolver request mapping template, I am able to call the API Gateway as long as it is not configured to authorize with IAM.
HTTP Resolver Request Mapping Template
{
"version": "2018-05-29",
"method": "POST",
## E.G. if full path is https://api.xxxxxxxxx.com/posts then resourcePath would be /posts **
"resourcePath": "/Prod/test",
"params":{
"body":$util.toJson($ctx.args)
}
}
Working Response
{
"data": {
"test": "Hello from Lambda!"
}
}
Now I'm trying to call the API Gateway with the http resolver after I lock down the gateway with IAM. I use the following request mapping template to try and pass the fields and headers required, but I get an error. Not really sure where to go from here.
Request Mapping Template Trying for IAM
{
"version": "2018-05-29",
"method": "POST",
## E.G. if full path is https://api.xxxxxxxxx.com/posts then resourcePath would be /posts **
"resourcePath": "/Prod/test",
"params":{
"body":$util.toJson($ctx.args),
"headers":{
"Authorization": "$ctx.request.headers.httpAuth",
"Content-Type": "$ctx.request.headers.conType",
"X-Amz-Security-Token": "$ctx.request.headers.secToken",
"x-amz-date": "$ctx.request.headers.newDate"
}
}
}
Error Received
"{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.
The Canonical String for this request should have been
'POST
/Prod/test
content-type:application/json; charset=UTF-8
host:q1gyu9a0he.execute-api.us-east-1.amazonaws.com
x-amz-date:20190209T103353Z
x-amz-security-token:AgoGb3JpZ2luEF4aCXVzLWVhc3QtMSKAAi+vyglsAoh1DS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z/5OXDs7n9s94iHRhOFj038akBB/Ye2v5fBEkPBbmGelD+7CGVNmMKgpnqHlzNpm3q3Gu2tcElSuF/3kUm4Eg0ElJbsRDEnsy5qhWt1fpeBrscpsfyifnZZOHL7enen0cK/iJY8SeJFnImj6eNhL/ymOrV1Sls90JF89F3tZfUvAGkwkdn64gU=
content-type;host;x-amz-date;x-amz-security-token
583ff6a2cabb532c16553f12958ec329caf1fe48d171d529b5e144f7a2c3f8f5'
The String-to-Sign should have been
'AWS4-HMAC-SHA256
20190209T103353Z
20190209/us-east-1/execute-api/aws4_request
2dcd7c552c2fec47b88e6f7d711b9a61879d8a12fc327a1a3f327287405ca0e5'
}"

AppSync can also compute the sigv4 signature required by Api Gateway on your behalf if you are using HTTP resolvers.
The configuration changes to your HTTP data source are not available through the console but using the AWS CLI you can pass the following paramaters:
aws appsync update-data-source --api-id yojcj4cdzzhizkscqocnr5xhem --name ApiGatewayTest --type HTTP --service-role-arn arn:aws:iam::769682826941:role/ApiGatewayRole --http-config file:///home/yourdir/apigateway.json
and the json file containing:
{
"endpoint": "https://apigateway.us-east-1.amazonaws.com/",
"authorizationConfig": {
"authorizationType": "AWS_IAM",
"awsIamConfig": {
"signingRegion": "us-east-1",
"signingServiceName": "apigateway"
}
}
}
AppSync does assume role on the role you provide, so it needs to allow AppSync to assume the role and call your API Gateway API.
You can find more info about the headers API Gateway expects in their documentation, here:
https://docs.aws.amazon.com/apigateway/api-reference/signing-requests/

Related

Javascript Fetch Authorization Header

I know, there are a lot of those questions out here but none of them seem to help me with my question so im sorry if im just not able to understand the other questions, so here i come:
I want to use oauth wit discogs.com Prodiver in my react-native app. Since no oauth library fit for Discogs i need to implement this on my own. Discogs documentation tells me which headers i need for my oauth flow (currently at 'request token' step):
Content-Type: application/x-www-form-urlencoded
Authorization:
OAuth oauth_consumer_key="your_consumer_key",
oauth_nonce="random_string_or_timestamp",
oauth_signature="your_consumer_secret&",
oauth_signature_method="PLAINTEXT",
oauth_timestamp="current_timestamp",
oauth_callback="your_callback"
User-Agent: some_user_agent
How can i make a get request with javascript and fetch and include those headers? My code right now seems fine to a beginner like me, but it wont get approved by discogs oauth endpoint:
const header = new Headers({
'Content-Type': 'application/x-www-form-urlencoded',
'Accept': 'application/vnd.discogs.v2.plaintext+json',
Authorization: {
'OAuth oauth_consumer_key': config.consumerKey, //imported from json
'oauth_nonce': nonce, //variable
'oauth_signature': config.consumerSecret, // imported from json
'oauth_signature_method': "PLAINTEXT",
'oauth_timestamp': timestamp, // variable
'oauth_callback': callback // variable
},
'User-Agent': config.appUserAgent
})
console.log(header)
const response = await fetch(https://api.discogs.com/oauth/request_token, {
method: 'GET',
headers: header
});
console.log(response)
The console log of headers and response logs this:
{
"map": {
"content-type": "application/x-www-form-urlencoded",
"accept": "application/vnd.discogs.v2.plaintext+json",
"authorization": "[object Object]",
"user-agent": "Jukebox/1.0"
}
}
{"_bodyBlob": {"_data": {"__collector": [Object], "blobId": "F020B207-2E76-46C8-AD23-783A582B873D", "name": "request_token.json", "offset": 0, "size": 90, "type": "application/json"}}, "_bodyInit": {"_data": {"__collector": [Object], "blobId": "F020B207-2E76-46C8-AD23-783A582B873D", "name": "request_token.json", "offset": 0, "size": 90, "type": "application/json"}}, "bodyUsed": false, "headers": {"map": {"access-control-allow-headers": "Content-Type, authorization, User-Agent, Private-Auth-Secret, Discogs-UID", "access-control-allow-methods": "HEAD,OPTIONS,OPTIONS", "access-control-allow-origin": "*", "access-control-expose-headers": "Location", "alt-svc": "h3=\":443\"; ma=86400, h3-29=\":443\"; ma=86400", "cf-cache-status": "DYNAMIC", "cf-ray": "79c05b750af01608-DUS", "content-language": "de", "content-length": "90", "content-type": "application/json", "date": "Sun, 19 Feb 2023 16:25:13 GMT", "server": "cloudflare", "strict-transport-security": "max-age=15552000", "x-content-type-options": "nosniff", "x-discogs-media-type": "discogs.v2", "x-discogs-ratelimit": "60", "x-discogs-ratelimit-remaining": "60", "x-discogs-ratelimit-used": "0", "x-frame-options": "SAMEORIGIN", "x-xss-protection": "1; mode=block"}}, "ok": false, "status": 500, "statusText": "", "type": "default", "url": "https://api.discogs.com/oauth/request_token"}
It looks like the Authorization header is not being set correctly in your request. Instead of setting it as an object, you need to set it as a single string that includes all the OAuth parameters.
Here's an example of how you can construct the Authorization header:
const oauthParams = {
oauth_consumer_key: config.consumerKey,
oauth_nonce: nonce,
oauth_signature: `${config.consumerSecret}&`,
oauth_signature_method: 'PLAINTEXT',
oauth_timestamp: timestamp,
oauth_callback: callback,
};
const authHeader = Object.entries(oauthParams)
.map(([key, value]) => `${encodeURIComponent(key)}="${encodeURIComponent(value)}"`)
.join(', ');
const headers = new Headers({
'Content-Type': 'application/x-www-form-urlencoded',
'Accept': 'application/vnd.discogs.v2.plaintext+json',
'Authorization': `OAuth ${authHeader}`,
'User-Agent': config.appUserAgent,
});
const response = await fetch('https://api.discogs.com/oauth/request_token', {
method: 'GET',
headers,
});
const data = await response.json();
console.log(data);
In this example, oauthParams is an object that holds all the OAuth parameters that need to be included in the Authorization header. The authHeader variable is constructed by encoding each key-value pair as a string in the format key="value", and joining them with commas. Finally, the Authorization header is set to "OAuth " + authHeader.
Note that the OAuth parameters must be sorted in alphabetical order by key before being encoded and included in the Authorization header.

How to handle sign up a user error while using Firebase REST API

I've been trying to sign up a user using Firebase Rest API using Node & Axios HTTP library.
I'm able to create a new user with email and password.
But when email already exists in the database or password is less than 6 characters, it doesn't show the proper errors.
It just returns Request failed with status code 400
Here is my code.
const config =
{
headers:
{
'Content-Type': 'application/json',
},
};
data = {
'email': "test#test.com",
'password': "password123",
'returnSecureToken': true
}
try
{
let signup = await axios.post('https://identitytoolkit.googleapis.com/v1/accounts:signUp?key=API_KEY',data,config)
res.json(signup.data);
}
catch(err)
{
res.json(err);
}
Error I get.
{
"message": "Request failed with status code 400",
"name": "Error",
"stack": "Error: Request failed with status code 400\n at createError (/Users/user/NodeJS/FirebaseAuth/node_modules/axios/lib/core/createError.js:16:15)\n at settle (/Users/user/NodeJS/FirebaseAuth/node_modules/axios/lib/core/settle.js:17:12)\n at IncomingMessage.handleStreamEnd (/Users/user/NodeJS/FirebaseAuth/node_modules/axios/lib/adapters/http.js:244:11)\n at IncomingMessage.emit (events.js:327:22)\n at endReadableNT (_stream_readable.js:1224:12)\n at processTicksAndRejections (internal/process/task_queues.js:84:21)",
"config": {
"url": "https://identitytoolkit.googleapis.com/v1/accounts:signUp?key=API_KEY",
"method": "post",
"data": "{\"email\":\"test#test.com\",\"password\":\"password123\",\"returnSecureToken\":true}",
"headers": {
"Accept": "application/json, text/plain, */*",
"Content-Type": "application/json",
"User-Agent": "axios/0.21.0",
"Content-Length": 75
},
"transformRequest": [
null
],
"transformResponse": [
null
],
"timeout": 0,
"xsrfCookieName": "XSRF-TOKEN",
"xsrfHeaderName": "X-XSRF-TOKEN",
"maxContentLength": -1,
"maxBodyLength": -1
}
}
Expected error here is : Email already exists. But it doesn't return this error.
What could be the issue here ?
Thanks!
By default firebase doesn't return response in the error body but it can be extracted with.
console.log(err.response.data.error);
This is not mentioned in the official firebase docs.

NodeJS - Send JSON object parameters with node-fetch

I'm trying to create a webhook via the GitHub API. The docs say that I need to provide a config parameter, which should be an object, but I'm not sure how I can send a JSON in the URL parameters. Here's what I've tried:
fetch(`https://api.github.com/repos/${repo.full_name}/hooks?config={"url": "https://webhooks.example.com", "content_type": "json"}`, {
method: "POST",
headers: {
Accept: "application/vnd.github.v3+json",
Authorization: `token ${account.accessToken}`
}
});
and
fetch(`https://api.github.com/repos/${repo.full_name}/hooks?config.url=https://webhooks.example.com&config.content_type=json`, {
method: "POST",
headers: {
Accept: "application/vnd.github.v3+json",
Authorization: `token ${account.accessToken}`
}
});
They both result in the following error:
{
"message": "Validation Failed",
"errors": [
{
"resource": "Hook",
"code": "custom",
"message": "Config must contain URL for webhooks"
}
],
"documentation_url": "https://developer.github.com/v3/repos/hooks/#create-a-hook"
}
How do I properly send a JSON object? I'm looking for a solution using node-fetch
When you are doing a post request, it's implied that there will be a payload and the lib you are using will be expecting a body property containing your payload.
So just add
fetch('https://api.github.com/repos/${repo.full_name}/hooks', {
method: "POST",
headers: {
Accept: "application/vnd.github.v3+json",
Authorization: `token ${account.accessToken}`
},
body:JSON.stringify(yourJSON) //here this is how you send your datas
});
And node-fetch will send your body with your request.
If you want more details on that i'll expand my answer
https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods here for a quick description of different http request type (verb)

Draftable.com API giving truncated response when passed a JSON in Google App Script

I am trying to call an API from draftable.com (https://api.draftable.com/v1/comparisons) using Google App Script. The API takes two files and returns a string. I have made the GET and DELETE functions which are working fine, but when I run a POST function I am getting an error at the
UrlFetchApp.fetch("URL",object);
Error: Request failed for https://api.draftable.com/v1/comparisons
returned code 400. Truncated server response: {"left":["This field is
required."],"right":["This field is required."]}
I am passing a JSON like the code below:
function POST() {
var options = {
"method": "POST",
"headers": {
"Content-Type": "multipart/form-data",
"Accept": "application/json",
"Authorization": "Token {iputmytokenhere}",
},
"left": {
"source_url": "https://api.draftable.com/static/test-documents/paper/left.pdf",
"display_name": "old-example.docx",
"file_type": "pdf"
},
"right": {
"source_url": "https://api.draftable.com/static/test-documents/paper/right.pdf",
"display_name": "newer-example.docx",
"file_type": "pdf"
}
};
var result = UrlFetchApp.fetch("https://api.draftable.com/v1/comparisons", options);
var params = JSON.parse(result.getContentText());
Logger.log(params.identifier);
}
}
Can anyone tell me why is the error coming.

Sendgrid integration with SAPUI5 app returns '400 Bad Request' on POST but works on Postman

I'm developing a cordova hybrid app that utilizes UI5 library. I need to be able to send as Email from the app so I decided to use Sendgrid API and, since I had issues with the NodeJS module, I'm creating an AJAX request. I've previously tested the request with Postman, being able to successfully send emails. But, as I tried to do the same request from the app, I've stumbled upon a status '400 Bad Request' without further information. Here goes the code snippet:
var settings = {
"async": true,
"crossDomain": true,
"url": "https://api.sendgrid.com/v3/mail/send",
"method": "POST",
"headers": {
"Content-Type": "application/json",
"Authorization": "Bearer [REDACTED]",
"cache-control": "no-cache"
},
"processData": false,
"data": {
"personalizations": [
{
"to": [
{
"email": "myemail#gmail.com"
}
],
"subject": "Contato do app"
}
],
"from": {
"email": "anotheremail#gmail.com"
},
"content": [
{
"type": "text/plain",
"value": formatEmail //variable with the email text
}
]
}
}
$.ajax(settings).then(
function success(response, status) {
dialog.close();
if (status == 202){
MessageBox.confirm('Mensagem enviada com sucesso', {
actions: [sap.m.MessageBox.Action.OK],
onClose: function(sAction){
that.onNavBack()
}
});
} else {
MessageBox.error('Erro!');
}
},
function fail(data, status){
dialog.close();
MessageBox.error('Request failed. Returned status of ' + status + ' DEBUGDATA: ' + JSON.stringify(data));
}
);
I really can't figure out the reason as to why this happens because the snippet generated by Postman is very similar to my code. Any help would be highly appreciated!
Thanks in advance
usually HTTP 400 means bad request and it means that you're passing the wrong parameters to the HTTP POST request.

Categories

Resources