protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken)
        {
            string payloadHash = null;

            if (this.includePayloadHash &&
                request.Method != HttpMethod.Get &&
                request.Content != null)
            {
                var hmac = System.Security.Cryptography.HMAC.Create(credential.Algorithm);
                hmac.Key = Encoding.ASCII.GetBytes(credential.Key);

                var task = request.Content.ReadAsByteArrayAsync().ConfigureAwait(false);
                var payload = task.GetAwaiter().GetResult();

                payloadHash = Convert.ToBase64String(hmac.ComputeHash(payload));
            }

            request.Headers.Host = request.RequestUri.Host;

            request.SignRequest(credential,
                this.ext,
                this.ts,
                this.nonce,
                payloadHash);

            return base.SendAsync(request, cancellationToken);
        }
        public void ShouldSignRequest()
        {
            var credential = new HawkCredential
            {
                Id = "456",
                Algorithm = "hmacsha256",
                Key = "werxhqb98rpaxn39848xrunpaw3489ruxnpa98w4rxn",
                User = "******"
            };

            var date = DateTime.Now;

            var ts = Hawk.ConvertToUnixTimestamp(date);
            var mac = Hawk.CalculateMac("example.com:8080", "get", new Uri("http://example.com:8080/resource/4?filter=a"), "hello", ts.ToString(), "k3j4h2", credential, "header");

            var authorization = string.Format("id=\"456\", ts=\"{0}\", nonce=\"k3j4h2\", mac=\"{1}\", ext=\"hello\"",
                ts, mac);

            var request = new HttpRequestMessage(HttpMethod.Get, "http://example.com:8080/resource/4?filter=a");
            request.SignRequest(credential, "hello", date, "k3j4h2", null);

            Assert.IsNotNull(request.Headers.Authorization != null);
            Assert.AreEqual(request.Headers.Authorization.Scheme, "Hawk");
            Assert.AreEqual(request.Headers.Authorization.Parameter, authorization);
        }
        protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken)
        {
            string payloadHash = null;

            if (this.includePayloadHash &&
                request.Method != HttpMethod.Get &&
                request.Content != null)
            {
                payloadHash = Hawk.CalculatePayloadHash(await request.Content.ReadAsStringAsync().ConfigureAwait(false),
                    request.Content.Headers.ContentType.MediaType,
                    credential);
            }

            request.Headers.Host = request.RequestUri.Host;

            request.SignRequest(credential,
                this.ext,
                this.ts,
                this.nonce,
                payloadHash);

            return await base.SendAsync(request, cancellationToken);
        }
        public void Tweet(string message)
        {
            string resourceUrl = Twitter.API_V1_1 + "statuses/update.json";
            if (string.IsNullOrEmpty(message))
            {
                throw new TwitterClientException("Tweet cannot be empty.");
            }

            if (message.Length > 140)
            {
                throw new TwitterClientException("Tweet cannot be longer than 140 characters.");
            }

            // This is the content
            var postData = new List<KeyValuePair<string, string>>();
            postData.Add(new KeyValuePair<string, string>("status",  message));

            // Load content
            HttpContent content = new FormUrlEncodedContent(postData);
            content.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded");

            // create a new Request Message
            HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Post, resourceUrl);
            requestMessage.Content = content;

            // Sign Request
            requestMessage.SignRequest(postData, this.authorization);

            var response = _client.SendAsync(requestMessage, HttpCompletionOption.ResponseHeadersRead).Result;
            HandleErrors(response);
        }