Exemplo n.º 1
0
        /// <summary>
        /// Sign OVH API REQUEST
        /// </summary>
        public static async Task SignRequestAsync(HttpRequestMessage request, IOvhApiCredentials credentials)
        {
            try
            {
                long   currentTimestamp  = OvhApiTools.Time(); //1608291240  //1608294594
                string requestdatastring = "";
                if (request.Content != null)
                {
                    requestdatastring = await request.Content.ReadAsStringAsync();
                }

                string target = request.RequestUri.ToString();
                if (!target.StartsWith("http"))
                {
                    target = target.TrimStart('/'); target = credentials.Endpoint.ToString() + target;
                }
                string signature = GenerateSignature(credentials.ApplicationSecret, credentials.ConsumerKey, currentTimestamp, request.Method.ToString().ToUpper(), target, requestdatastring);


                //request.Headers.Add("X-UID", "");
                request.Headers.Add(SHARED.OvhConstants.OVH_APP_HEADER, credentials.ApplicationKey);
                request.Headers.Add(SHARED.OvhConstants.OVH_CONSUMER_HEADER, credentials.ConsumerKey);
                request.Headers.Add(SHARED.OvhConstants.OVH_TIME_HEADER, currentTimestamp.ToString());
                request.Headers.Add(SHARED.OvhConstants.OVH_SIGNATURE_HEADER, signature);
                // headers.Add(OVH_BATCH_HEADER, ParameterSeparator.ToString());
            }
            catch (Exception ex)
            {
                throw new Exception("OVH SignRequestAsync " + ex.Message, ex);
            }
        }
Exemplo n.º 2
0
        public static HttpClient FactoryClient(IOvhApiCredentials credential)
        {
            HttpClient retour = new HttpClient()
            {
                BaseAddress = credential.Endpoint
            };

            return(retour);
        }
Exemplo n.º 3
0
 public DOMAINWrapper(IOvhApiCredentials credentials, System.Net.Http.HttpClient client = null)
 {
     this.Credentials = credentials;
     if (client != null)
     {
         this.client = client;
     }
     else
     {
         this.client = OvhApiTools.FactoryClient(this.Credentials);
     }
 }
Exemplo n.º 4
0
        public static async Task <TResponseModel> ExecuteWithModelAsync <TResponseModel>(this HttpClient client, IOvhApiCredentials credential, HttpMethod method, string urlPart, Dictionary <string, object> formdata = null, object model = null)
        {
            try
            {
                HttpRequestMessage req = new HttpRequestMessage(method, urlPart);
                if (model != null)
                {
                    req.Content = OvhApiTools.JsonContent(model);
                }
                await OvhApiTools.SignRequestAsync(req, credential);

                HttpResponseMessage resp = await client.SendAsync(req);

                OvhApiTools.Validate(resp);
                TResponseModel retour = await OvhApiTools.ReadWithModelAsync <TResponseModel>(resp);

                return(retour);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Exemplo n.º 5
0
 public static async Task <AUTH.CredentialResponseModel> OvhAuthRequestAsync(IOvhApiCredentials credential, AUTH.CredentialRequestModel credential1)
 => await new AUTH.AUTHWrapper(credential).OvhAuthRequestAsync(credential1);