Beispiel #1
0
        private static void Send()
        {
            var config = new AwsConfig
            {
                Region   = "eu-west-1",
                Service  = "ses",
                AccessId = "<ACCESSID>",
                Secret   = "<SECRET>"
            };

            var from    = "*****@*****.**";
            var to      = "*****@*****.**";
            var request = new HttpRequestMessage
            {
                Method = HttpMethod.Get,
                // Optional content
                //Content = new StringContent(string.Empty, Encoding.UTF8, "application/x-www-form-urlencoded"),
                RequestUri = new Uri($"https://email.eu-west-1.amazonaws.com?Action=SendEmail&Source={from}&Destination.ToAddresses.member.1={to}&Message.Subject.Data=AmazonMail&Message.Body.Text.Data=SigningTest&ConfigurationSetName=ExtraInfo")
            };

            AwsSigner.SignRequest(config, request).GetAwaiter().GetResult();

            var client = new HttpClient();
            var result = client.SendAsync(request).GetAwaiter().GetResult();

            result.EnsureSuccessStatusCode();
            Console.WriteLine("All good");
        }
        public async Task SignRequest()
        {
            var signer          = new AwsSigner();
            var config          = Helpers.CreateExampleConfig();
            var expectedRequest = Helpers.CreateExampleRequest();
            var request         = Helpers.CreateExampleRequest();

            //Remove the X-Amz-Date header since the authorize method should do this
            request.Headers.Remove("X-Amz-Date");

            var expectedDateTime = DateTimeOffset.Parse("2015-08-30T12:36:00Z");
            await AwsSigner.SignRequest(config, request, expectedDateTime);

            var signature = await signer.CreateSignature(config, expectedRequest, expectedDateTime);

            var expectedScheme  = "AWS4-HMAC-SHA256";
            var expectedContent = $"Credential=AKIDEXAMPLE/{expectedDateTime:yyyyMMdd}/us-east-1/iam/aws4_request, SignedHeaders=content-type;host;x-amz-date, Signature={signature}";

            Assert.AreEqual(expectedScheme, request.Headers.Authorization.Scheme, "Authorization scheme does not match");
            Assert.AreEqual(expectedContent, request.Headers.Authorization.Parameter, "Authorization content does not match");
        }
        public async Task SignRequestEmail()
        {
            var config = new AwsConfig
            {
                Region   = "eu-west-1",
                Service  = "ses",
                AccessId = "AKIDEXAMPLE",
                Secret   = "wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY"
            };
            var request = Helpers.CreateExampleRequest();

            request.Content = new StringContent(string.Empty, Encoding.ASCII, "application/x-www-form-urlencoded");
            //Remove the X-Amz-Date header since the authorize method should do this
            request.Headers.Remove("X-Amz-Date");

            var expectedDateTime = DateTimeOffset.Parse("2018-06-12T20:58:15Z");
            await AwsSigner.SignRequest(config, request, expectedDateTime);

            var          expectedScheme  = "AWS4-HMAC-SHA256";
            const string expectedContent = "Credential=AKIDEXAMPLE/20180612/eu-west-1/ses/aws4_request, SignedHeaders=content-type;host;x-amz-date, Signature=8675e236d7864e374cb7d8986204275cb191680357c7b1897103a9c4e2547b2c";

            Assert.AreEqual(expectedScheme, request.Headers.Authorization.Scheme, "Authorization scheme does not match");
            Assert.AreEqual(expectedContent, request.Headers.Authorization.Parameter, "Authorization content does not match");
        }