Esempio n. 1
0
        public HttpRequestMessage PingRequest()
        {
            var message = new HttpRequestMessage(HttpMethod.Get, $"https://{host}/{prefix}/ping");

            message.Headers.Add("Date", DuoApiHelper.DateToRFC822(DateTime.Now));
            return(message);
        }
Esempio n. 2
0
        private HttpRequestMessage buildMessage(HttpMethod method, string endpoint, params KeyValuePair <string, string>[] parameters)
        {
            // Url Encoded Parameters
            var urlParams = string.Empty;

            if (parameters.Any())
            {
                urlParams = DuoApiHelper.CanonicalizeParams(parameters);
            }

            // Date
            var dateStr = DuoApiHelper.DateToRFC822(DateTime.Now);

            // Init Message
            var mUpper = method.Method.ToUpper();
            HttpRequestMessage message;

            if ((mUpper == "GET" || mUpper == "DELETE") && !string.IsNullOrWhiteSpace(urlParams))
            {
                message = new HttpRequestMessage(method, $"https://{host}/{prefix}/{endpoint}?{urlParams}");
            }
            else
            {
                message = new HttpRequestMessage(method, $"https://{host}/{prefix}/{endpoint}");
            }

            // Headers
            message.Headers.Add("Accept", "application/json");
            message.Headers.Add("Host", host);
            message.Headers.Add("Date", dateStr);
            message.Headers.Add("X-Duo-Date", dateStr);

            // Signature
            var signature = DuoApiHelper.CanonicalizeRequest(
                mUpper,
                host.ToLower(),
                $"/{prefix}/{endpoint}",
                urlParams,
                dateStr);

            // Authorization
            var signed = DuoApiHelper.HmacSign(secretKey, signature);
            var auth   = $"{integrationKey}:{signed}";

            message.Headers.Add("Authorization", $"Basic {DuoApiHelper.Encode64(auth)}");

            // Add Content Body if POST
            if (mUpper == "POST")
            {
                message.Content = new FormUrlEncodedContent(parameters);
            }

            return(message);
        }