tsibelman / aws-signer-v4-dot-net

Sign HttpRequestMessage using AWS Signature v4 using request information and credentials.
Apache License 2.0
72 stars 27 forks source link

HTML encode parts of URI #9

Closed StNimmerlein closed 5 years ago

StNimmerlein commented 5 years ago

Currently (at least with the version released on NuGet) requests to the WebSocket ApiGateway are not possible since AWS expects the parts of the URI (eg /@connections) to be HTML encoded (eg /%40connections). This patch adds the encoding.

StNimmerlein commented 5 years ago

Oh, I just noticed I compiled it in .NETCore 2.1. To use it in .NETStandard 2/.NETFramework 4.5 you need to replace the double quotes in .Split("/") by single quotes. My bad :(

Quentinb commented 5 years ago

Have you managed to get this to work with Websockets? I used my own code but keep getting the dreaded "The request signature we calculated does not match.." message (Copy/pasting the results into a text file, they match what AWS says they are meant to be).

Using this package, I get the same result. I'm assuming at this point it is the URL encoding (@ and =) as your update has not been merged?.

For websockets, I want to send a payload (with POST) and it does not look like this package includes the body payload into the signing request. Happy to add the feature, but right now getting any example to not return a "The request signature we calculated does not match" would be greatly appreciated.

Update Managed to get it working for websockets! I was missing the POST body from the example code and applied the changes from @StNimmerlein to do the URL encoding.

My simple console app test: ` var request = new HttpRequestMessage { Method = HttpMethod.Post, RequestUri = new Uri("https://apigatewayId>.execute-api.<region>.amazonaws.com/dev/@connections/<connectionId"), Content = new StringContent("{\"data\":\"Hello from server\"}") };

var signer = new AWS4RequestSigner("", ""); request = signer.Sign(request, "execute-api", "").Result;

var client = new HttpClient(); var response = client.SendAsync(request).Result;

var responseStr = response.Content.ReadAsStringAsync().Result; Console.WriteLine(responseStr); `