Beispiel #1
0
        public auth gettokenbyrefresh(string tenantId)
        {
            Dictionary <string, string> d = new Dictionary <string, string>();

            d.Add(Constants.grant_type, Constants.client_credentials);
            d.Add(Constants.client_id, Appcontext.client_id);
            d.Add(Constants.client_secret, Appcontext.client_secret);
            d.Add(Constants.resource, Appcontext.resource);
            string s = PHPRequests.RequestToPHPSync(d, Appcontext.urlof365 + tenantId + "/oauth2/token");
            JavaScriptSerializer js = new JavaScriptSerializer();
            auth authres            = js.Deserialize <auth>(s);

            return(authres);
        }
Beispiel #2
0
        //public static string GetRequestByUrl(string urlToRequest,auth a)
        //{
        //    string responseAT = null;
        //    try
        //    {
        //        HttpWebRequest requestGC = WebRequest.Create(urlToRequest) as HttpWebRequest;
        //        requestGC.Method = "GET";
        //        requestGC.Headers.Add("Authorization", "Bearer "+ a.access_token);
        //        StringBuilder postData = new StringBuilder();
        //        HttpWebResponse response = requestGC.GetResponse() as HttpWebResponse;
        //        if (response != null)
        //        {
        //            using (var sr = new StreamReader(response.GetResponseStream()))
        //            {
        //                responseAT = sr.ReadToEnd();
        //            }
        //        }

        //    }
        //    catch (Exception ex)
        //    {
        //        throw ex;
        //    }
        //    return responseAT;
        //}

        public static string HttpRequest(string urlToRequest, string json, auth a, string Method, string contentType)
        {
            string responseAT = null;

            try
            {
                HttpWebRequest requestGC = WebRequest.Create(urlToRequest) as HttpWebRequest;
                requestGC.Method = Method;
                requestGC.Headers.Add("Authorization", "Bearer " + a.access_token);
                StringBuilder postData = new StringBuilder();

                if (json != string.Empty)
                {
                    requestGC.ContentType   = contentType;
                    requestGC.ContentLength = json.Length;
                    using (var streamWriter = new StreamWriter(requestGC.GetRequestStream()))
                    {
                        streamWriter.Write(json);
                        streamWriter.Flush();
                        streamWriter.Close();
                    }
                }


                HttpWebResponse response = requestGC.GetResponse() as HttpWebResponse;
                if (response != null)
                {
                    using (var sr = new StreamReader(response.GetResponseStream()))
                    {
                        responseAT = sr.ReadToEnd();
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(responseAT);
        }
Beispiel #3
0
        public Functions()
        {
            Authentication a = new Authentication();

            this.Authetication = a.gettokenbyrefresh("1e08xxxxxxxxxxx");
        }