Support uri parameter#28
Conversation
pahud
commented
Jul 9, 2016
- initial support for AWS API Gateway
- Custom doamin name support with API Gateway
- when request.uri is provided, npm modules like request and request-promise are also supported
- examples provided
… domain name 2. when request.uri is provided, generate all required parameters and support request module as well
|
Would be great to merge in if this is finished! |
|
@Dayjo the title was misleading – API Gateway has been supported by
In any case, you should be able to use API Gateway without needing this PR in |
|
Hi @mhart thanks, I kind of hoped / assumed the reason my signature is 100% always erroring was because of this haha. Damn. Back to the drawing board. |
|
@Dayjo what does your code look like? |
|
Well it's been butchered several times to try and get it working. I'm trying to do signed requests across AJAX for a JS app. I was trying to manually just use the headers created by aws4 with my ajax request, but to no avail. for instance; var d = new Date();
d = new Date(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate(), d.getUTCHours(), d.getUTCMinutes(), d.getUTCSeconds());
CONFIG.dateStamp = d.yyyymmdd();
CONFIG.dateTimeStamp = d.yyyymmddhis();
var test = aws4.sign({
uri: url,
service: 'execute-api',
region: CONFIG.REGION
},
{
accessKeyId: CONFIG.ACCESS_KEY,
secretAccessKey: CONFIG.SECRET_KEY
});
//'AWS4-HMAC-SHA256 Credential=' + CONFIG.ACCESS_KEY + '/' + CONFIG.dateStamp + '/' + CONFIG.REGION + '/execute-api/aws4_request, SignedHeaders=content-length;content-type;host;x-amz-date;x-amz-security-token, Signature=' + CONFIG.SIGNED_KEY,
var headers = {
'Authorization': test.headers['Authorization'],
'X-Amz-Date': CONFIG.dateTimeStamp,
'X-Amz-Security-Token': CONFIG.SECURITY_TOKEN
};
// Make the request
$.ajax({
type: type,
url: url,
headers: headers
});
// ----- Date functions for date/time 'stamps'
Date.prototype.yyyymmdd = function() {
var mm = this.getMonth() + 1; // getMonth() is zero-based
var dd = this.getDate();
return [this.getFullYear(), !mm[1] && '0', mm, !dd[1] && '0', dd].join(''); // padding
};
Date.prototype.yyyymmddhis = function() {
var d = this.yyyymmdd();
var time = this.toTimeString();
var ts = time.substr(0,8).replace(/:/g,"");
return d + 'T' + ts + 'Z';
};Any suggestions, or if I'm doing something utterly stupid it'd be great to know haha. |
|
@Dayjo - yeah, I see a bunch of things. Firstly, the Secondly, you shouldn't modify the headers after the signing – you should just pull the headers out exactly as they are in the signed request. I'm not sure what all the date stuff is ( So try something like this: var opts = aws4.sign({
host: 'my-execute-api-host.com',
path: '/some/path',
service: 'execute-api',
region: CONFIG.REGION,
}, {
accessKeyId: CONFIG.ACCESS_KEY,
secretAccessKey: CONFIG.SECRET_KEY,
sessionToken: CONFIG.SECURITY_TOKEN,
})
return $.ajax({
url: 'https://' + opts.host + opts.path,
headers: opts.headers,
})(I'm assuming you're doing GETs – if you're doing POSTs, then you should pass a |
|
Haha yeah, unfortunately the rest of the app is using it anyway, thanks for the info, will give it a shot! |
Edit: See comment below for fix.@mhart unfortunately I'm now getting a javascript error from within the aws4 module :(. I get I believe this is because I may incorrectly configured the 'browser' version. Do you think you could give me a little run down of the process for building this for the browser? I've read https://github.com/mhart/aws4/tree/master/browser but still not 100% sure what I actually need to do. I'm already using browsify to load in the aws4 module, but not sure what the build process is for or if it's necessary. If you like I can start up a new issue with this info in? |
|
So I managed to fix my above js errors by using; https://github.com/mathiasvr/querystring though i've not yet been able to get aliasify working to actually alias it, had to fork and created a And now it appears to be working ok, need to do more tests but my requests seem to be signed ok :) Thanks a bunch @mhart - might be good to add the query string fix to the browser readme file :) |
|
@Dayjo I'm really not sure what you mean – the example in the browser README works perfectly for me. I do: And it all works fine. Can you explain what problems you ran into with it? |
|
@mhart I think I'm just unfamiliar with build scripts and such in npm 😄 - we mostly use gulp - this did work for me, thanks! |
