in GameLiftExampleUnityProject/Assets/Scripts/Client/MatchmakingClient.cs [92:150]
HttpRequestMessage generateSignedRequest(string url)
{
var endpointUri = url;
var uri = new Uri(endpointUri);
var headers = new Dictionary<string, string>
{
{AWS4SignerBase.X_Amz_Content_SHA256, AWS4SignerBase.EMPTY_BODY_SHA256},
};
var signer = new AWS4SignerForAuthorizationHeader
{
EndpointUri = uri,
HttpMethod = "GET",
Service = "execute-api",
Region = regionString
};
//Extract the query parameters
var queryParams = "";
if (url.Split('?').Length > 1)
{
queryParams = url.Split('?')[1];
}
var authorization = signer.ComputeSignature(headers,
queryParams,
AWS4SignerBase.EMPTY_BODY_SHA256,
Client.cognitoCredentials.AccessKey,
Client.cognitoCredentials.SecretKey);
headers.Add("Authorization", authorization);
var request = new HttpRequestMessage
{
Method = HttpMethod.Get,
RequestUri = new Uri(url),
};
// Add the generated headers to the request
foreach (var header in headers)
{
try
{
if (header.Key != null && header.Value != null)
request.Headers.Add(header.Key, header.Value);
}
catch (Exception e)
{
Debug.Log("error: " + e.GetType().ToString());
}
}
// Add the IAM authentication token
request.Headers.Add("x-amz-security-token", Client.cognitoCredentials.Token);
return request;
}