//////////////////////////////////////////////////////////////////////////////// public static Dictionary <string, string> GetHeadersV1(string sAuthorization, string sSecret, string sMethod, string sURL, string sBody) { var dtDate = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ssZ"); var sFingerprint = RequestSignature.GetFingerprintV1(sAuthorization, dtDate, sMethod, sURL, sBody); var sSignature = RequestSignature.GetSignatureV1(sAuthorization, dtDate, sFingerprint, sSecret); var headersV1 = new Dictionary <string, string>(); headersV1.Add("Ezmax-Date", dtDate); headersV1.Add("Ezmax-Fingerprint", sFingerprint); headersV1.Add("Ezmax-Signature", sSignature); return(headersV1); }
//////////////////////////////////////////////////////////////////////////////// public static void InjectSecurityHeaders(ref Dictionary <String, String> headerParams, Method method, Object postBody, string path, Dictionary <String, String> pathParams, List <KeyValuePair <String, String> > queryParams) { //Get Autorization ////////////////// var sAuthorization = Configuration.Default.GetApiKeyWithPrefix("Authorization"); //Get Secret //////////// var sSecret = Configuration.Default.GetApiKeyWithPrefix("secret"); if (sSecret == null) { sSecret = ""; } //Get Method //////////// var sMethod = method.ToString(); //We need to recreate the full URL ////////////////////////////////// var sURL = Configuration.Default.ApiClient.RestClient.BaseUrl.ToString(); sURL += path; //Put the pathParams back in URL foreach (var param in pathParams) { sURL = sURL.Replace("{" + param.Key + "}", ApiClient.UrlEncode(param.Value)); } //Put the queries back in URL if (queryParams != null) { if (queryParams.Count > 0) { sURL += "?"; } var iRemain = queryParams.Count; foreach (KeyValuePair <string, string> entry in queryParams) { sURL += ApiClient.UrlEncode(entry.Key) + "=" + ApiClient.UrlEncode(entry.Value); iRemain -= 1; if (iRemain > 0) { sURL += "&"; } } } //Exctact the body ////////////////// var sBody = ""; if (postBody != null) { sBody = postBody.ToString(); } //Get the 3 signature headers ///////////////////////////// var headersV1 = RequestSignature.GetHeadersV1(sAuthorization: sAuthorization, sSecret: sSecret, sMethod: sMethod, sURL: sURL, sBody: sBody); //Inject the new headers in the headers /////////////////////////////////////// headerParams = headerParams.Concat(headersV1).ToDictionary(x => x.Key, x => x.Value); }