/// <summary>
        ///     Populates the httpClient with signed request headers and the POST body data.
        /// </summary>
        /// <param name="message">
        ///     The http request message.
        /// </param>
        /// <param name="postBody">
        ///     The post body data of the request.
        /// </param>
        /// <param name="contentType">
        ///     Either JSON or XML.
        /// </param>
        /// <param name="developerKey">
        ///     The developer key used to create the signed header.
        /// </param>
        /// <param name="developerSecret">
        ///     The developer secret used to create the signed header.
        /// </param>
        private void CreateRequestHeaders(HttpRequestMessage message, string postBody, string contentType, string developerKey, string developerSecret)
        {
            AuthorizationHeader authorizationHeader = AuthorizationHeader.Create(message.Headers, message.RequestUri, postBody, message.Method.Method, "1.0", "TP-HMAC-SHA1", Guid.NewGuid().ToString(), DateTime.UtcNow.ToString("O"), developerKey, developerSecret);

            message.Headers.Add("tp-authorization", authorizationHeader.ToString());
            message.Headers.Add("tp-application-id", "1234");
            message.Headers.Add("tp-application-name", "triPOS.CSharp");
            message.Headers.Add("tp-application-version", "1.0.0");
            message.Headers.Add("tp-return-logs", "false");
            message.Headers.Add("accept", contentType);
            message.Content = new StringContent(postBody, Encoding.UTF8, contentType);
        }
Esempio n. 2
0
        protected AuthorizationHeader CreateAuthHeader(HttpWebRequest request)
        {
            var parameters = new HttpParameterSet()
            {
                // From AuthConfig
                ConsumerKey     = config.ConsumerKey,
                ConsumerSecret  = config.ConsumerSecret,
                Token           = config.Token,
                TokenSecret     = config.TokenSecret,
                OAuthVersion    = config.OAuthVersion,
                SignatureMethod = config.SignatureMethod,

                // Derived from HTTP Web Request
                Url           = request.RequestUri.OriginalString,
                RequestMethod = request.Method,
                PostData      = postData,
            };

            return(AuthorizationHeader.Create(parameters));
        }