private void AggregateModel(GlueCompany company, string model_id) { if (this.connectedHost != company) { ConnectToCompany(company); } var sig = GetSignature(company); var req = new RestRequest($"https://{baseUrlB4}:443/api/model/v1/aggregate.json", Method.POST); req.AddParameter("company_id", this.connectedHost.company_id); req.AddParameter("api_key", sig.publicKey); req.AddParameter("auth_token", sig.authToken); req.AddParameter("timestamp", sig.timestamp); req.AddParameter("sig", sig.signature); req.AddParameter("model_id", model_id); var res = client.Execute(req); if (!res.IsSuccessful) { throw new Exception(res.StatusCode.ToString()); } }
private GlueFile GetModelInfo(GlueCompany company, GlueProject project, string model_id, string version_id = null) { if (this.connectedHost != company) { ConnectToCompany(company); } var sig = GetSignature(company); var req = new RestRequest($"https://{baseUrlB4}:443/api/model/v2/info.json"); req.AddParameter("company_id", this.connectedHost.company_id); req.AddParameter("api_key", sig.publicKey); req.AddParameter("auth_token", sig.authToken); req.AddParameter("timestamp", sig.timestamp); req.AddParameter("sig", sig.signature); req.AddParameter("model_id", model_id); req.AddParameter("version_id", version_id); var res = client.Execute(req); if (!res.IsSuccessful) { throw new Exception(res.StatusCode.ToString()); } var modelInfo = JsonConvert.DeserializeObject <GlueFile>(res.Content); modelInfo.Project = project; return(modelInfo); }
private void ConnectToCompany(ICompany company) { this.connectedHost = null; var b2Cookies = client.CookieContainer.GetCookies(new Uri($"https://{baseUrlB2}")).Cast <Cookie>(); // set g_as, g_h cookies to "" foreach (var cookie in b2Cookies) { if (cookie.Name == "g_as" || cookie.Name == "g_h") { cookie.Value = "\"\""; } } var req = new RestRequest($"https://{baseUrlB2}/GlueHostServlet?host={company.Id}"); req.AddHeader("X-Requested-With", "XMLHttpRequest"); req.AddHeader("Referer", $"https://{baseUrlB2}/host"); // cookies not set from 302 Redirect page // disable redirects for this request to get cookies client.FollowRedirects = false; var res = client.Execute(req); if (res.StatusCode != HttpStatusCode.Redirect) { throw new Exception(res.StatusCode.ToString()); } client.FollowRedirects = true; foreach (var cookie in res.Cookies) { // cookies not setting from .autodesk.com // remove . from beginning of domain and set path to / var fixedDomain = cookie.Domain.StartsWith(".") ? cookie.Domain.Remove(0, 1) : cookie.Domain; var c = new Cookie(cookie.Name, cookie.Value, "/", fixedDomain); client.CookieContainer.Add(c); } var req2 = new RestRequest(res.ResponseUri); var res2 = client.Execute(req2); b2Cookies = client.CookieContainer.GetCookies(new Uri($"https://{baseUrlB2}")).Cast <Cookie>(); var g_as = b2Cookies.Where(x => x.Name == "g_as").SingleOrDefault(); var g_h = b2Cookies.Where(x => x.Name == "g_h").SingleOrDefault(); // if g_as, g_h cookies not set if (g_as == null || g_h == null || g_as.Value == "\"\"" || g_h.Value == "\"\"") { throw new Exception("Could not connect to host"); } else { this.connectedHost = (GlueCompany)company; } }
private Signature GetSignature(GlueCompany company) { if (this.connectedHost != company) { ConnectToCompany(company); } var req = new RestRequest($"https://{baseUrlB2}/GlueApiServlet?api=getSignature"); req.AddHeader("X-Requested-With", "XMLHttpRequest"); req.AddHeader("Referer", $"https://{baseUrlB2}/i/{company.company_id}"); var res = client.Execute(req); if (!res.IsSuccessful) { throw new Exception(res.StatusCode.ToString()); } return(JsonConvert.DeserializeObject <Signature>(res.Content)); }
public void Login() { var username = this.IsStaging ? "*****@*****.**" : "*****@*****.**"; var password = "******"; IsLoggedIn = false; this.connectedHost = null; // initialize client client = new RestClient(); client.CookieContainer = new CookieContainer(); // login page var req1 = new RestRequest($"https://{baseUrlB2}/login"); var res1 = client.Execute(req1); if (!res1.IsSuccessful) { throw new Exception(res1.StatusCode + " " + res1.StatusDescription); } // click login var req2 = new RestRequest($"https://{baseUrlB2}//consumer?openid_identifier=https://{baseUrlAccounts}&inIFrame=1"); var res2 = client.Execute(req2); if (!res2.IsSuccessful) { throw new Exception(res2.StatusCode + " " + res2.StatusDescription); } var body2 = res2.Content; var authKey = Regex.Match(body2, @"AuthKey%3D([a-z0-9-]+)""").Groups[1]; var token = Regex.Match(body2, @"name=""__RequestVerificationToken"" type=""hidden"" value=""([^""]+)""").Groups[1]; // submit username var req3 = new RestRequest( $"https://{baseUrlAccounts}/Authentication/IsExistingUser?viewmode=iframe&ReturnUrl=%2Fauthorize%3Fviewmode%3Diframe%26lang%3Den-US%26realm%3D{baseUrlB2}%26ctx%3Dbim360w%26AuthKey%3D{authKey}", Method.POST); req3.AddParameter("__RequestVerificationToken", token); req3.AddParameter("Username", username); var res3 = client.Execute(req3); if (!res3.IsSuccessful) { throw new Exception(res3.StatusCode + " " + res3.StatusDescription); } // submit password var req4 = new RestRequest( $"https://{baseUrlAccounts}/Authentication/LogOn?viewmode=iframe&ReturnUrl=%2Fauthorize%3Fviewmode%3Diframe%26lang%3Den-US%26realm%3D{baseUrlB2}%26ctx%3Dbim360w%26AuthKey%3D{authKey}", Method.POST); req4.AddParameter("__RequestVerificationToken", token); req4.AddParameter("queryStrings", $"?viewmode=iframe&ReturnUrl=%2Fauthorize%3Fviewmode%3Diframe%26lang%3Den-US%26realm%3D{baseUrlB2}%26ctx%3Dbim360w%26AuthKey%3D{authKey}"); req4.AddParameter("signinThrottledMessage", "You+have+made+too+many+sign+in+attempts+recently.+Please+try+again+later."); req4.AddParameter("UserName", username); req4.AddParameter("Password", password); req4.AddParameter("RememberMe", false); var res4 = client.Execute(req4); if (!res4.IsSuccessful) { throw new Exception(res4.StatusCode + " " + res4.StatusDescription); } var body4 = res4.Content; // finalize auth var req5 = new RestRequest( $"https://{baseUrlB2}/consumer?is_return=true&isIFrame=true", Method.POST); req5.AddParameter("openid.claimed_id", Regex.Match(body4, @"<input type=""hidden"" name=""openid\.claimed_id"" value=""([^""]*)"" />").Groups[1]); req5.AddParameter("openid.identity", Regex.Match(body4, @"<input type=""hidden"" name=""openid\.identity"" value=""([^""]*)"" />").Groups[1]); req5.AddParameter("openid.sig", Regex.Match(body4, @"<input type=""hidden"" name=""openid\.sig"" value=""([^""]*)"" />").Groups[1]); req5.AddParameter("openid.signed", Regex.Match(body4, @"<input type=""hidden"" name=""openid\.signed"" value=""([^""]*)"" />").Groups[1]); req5.AddParameter("openid.assoc_handle", Regex.Match(body4, @"<input type=""hidden"" name=""openid\.assoc_handle"" value=""([^""]*)"" />").Groups[1]); req5.AddParameter("openid.op_endpoint", Regex.Match(body4, @"<input type=""hidden"" name=""openid\.op_endpoint"" value=""([^""]*)"" />").Groups[1]); req5.AddParameter("openid.return_to", Regex.Match(body4, @"<input type=""hidden"" name=""openid\.return_to"" value=""([^""]*)"" />").Groups[1].Value.Replace("&", "&")); req5.AddParameter("openid.response_nonce", Regex.Match(body4, @"<input type=""hidden"" name=""openid\.response_nonce"" value=""([^""]*)"" />").Groups[1]); req5.AddParameter("openid.mode", Regex.Match(body4, @"<input type=""hidden"" name=""openid\.mode"" value=""([^""]*)"" />").Groups[1]); req5.AddParameter("openid.ns", Regex.Match(body4, @"<input type=""hidden"" name=""openid\.ns"" value=""([^""]*)"" />").Groups[1]); req5.AddParameter("openid.ns.alias3", Regex.Match(body4, @"<input type=""hidden"" name=""openid\.ns\.alias3"" value=""([^""]*)"" />").Groups[1]); req5.AddParameter("openid.alias3.request_token", Regex.Match(body4, @"<input type=""hidden"" name=""openid\.alias3\.request_token"" value=""([^""]*)"" />").Groups[1]); req5.AddParameter("openid.alias3.scope", Regex.Match(body4, @"<input type=""hidden"" name=""openid\.alias3\.scope"" value=""([^""]*)"" />").Groups[1]); req5.AddParameter("openid.ns.alias4", Regex.Match(body4, @"<input type=""hidden"" name=""openid\.ns\.alias4"" value=""([^""]*)"" />").Groups[1]); req5.AddParameter("openid.alias4.mode", Regex.Match(body4, @"<input type=""hidden"" name=""openid\.alias4\.mode"" value=""([^""]*)"" />").Groups[1]); req5.AddParameter("openid.alias4.type.alias1", Regex.Match(body4, @"<input type=""hidden"" name=""openid\.alias4\.type\.alias1"" value=""([^""]*)"" />").Groups[1]); req5.AddParameter("openid.alias4.value.alias1", Regex.Match(body4, @"<input type=""hidden"" name=""openid\.alias4\.value\.alias1"" value=""([^""]*)"" />").Groups[1]); req5.AddParameter("openid.alias4.type.alias2", Regex.Match(body4, @"<input type=""hidden"" name=""openid\.alias4\.type\.alias2"" value=""([^""]*)"" />").Groups[1]); req5.AddParameter("openid.alias4.value.alias2", Regex.Match(body4, @"<input type=""hidden"" name=""openid\.alias4\.value\.alias2"" value=""([^""]*)"" />").Groups[1]); req5.AddParameter("openid.alias4.type.alias3", Regex.Match(body4, @"<input type=""hidden"" name=""openid\.alias4\.type\.alias3"" value=""([^""]*)"" />").Groups[1]); req5.AddParameter("openid.alias4.value.alias3", Regex.Match(body4, @"<input type=""hidden"" name=""openid\.alias4\.value\.alias3"" value=""([^""]*)"" />").Groups[1]); req5.AddParameter("openid.alias4.type.alias4", Regex.Match(body4, @"<input type=""hidden"" name=""openid\.alias4\.type\.alias4"" value=""([^""]*)"" />").Groups[1]); req5.AddParameter("openid.alias4.value.alias4", Regex.Match(body4, @"<input type=""hidden"" name=""openid\.alias4\.value\.alias4"" value=""([^""]*)"" />").Groups[1]); req5.AddParameter("openid.alias4.type.alias5", Regex.Match(body4, @"<input type=""hidden"" name=""openid\.alias4\.type\.alias5"" value=""([^""]*)"" />").Groups[1]); req5.AddParameter("openid.alias4.value.alias5", Regex.Match(body4, @"<input type=""hidden"" name=""openid\.alias4\.value\.alias5"" value=""([^""]*)"" />").Groups[1]); var res5 = client.Execute(req5); if (!res5.IsSuccessful) { throw new Exception(res5.StatusCode + " " + res5.StatusDescription); } foreach (var cookie in res5.Cookies) { // cookies not setting from .autodesk.com // remove . from beginning of domain and set path to / var fixedDomain = cookie.Domain.StartsWith(".") ? cookie.Domain.Remove(0, 1) : cookie.Domain; var c = new Cookie(cookie.Name, cookie.Value, "/", fixedDomain); client.CookieContainer.Add(c); } var b2Cookies = client.CookieContainer.GetCookies(new Uri($"https://{baseUrlB2}")).Cast <Cookie>(); var g_id = b2Cookies.Where(x => x.Name == "g_id").SingleOrDefault(); var g_s = b2Cookies.Where(x => x.Name == "g_s").SingleOrDefault(); var oi_oid = b2Cookies.Where(x => x.Name == "oi_oid").SingleOrDefault(); if (g_id == null || g_s == null || oi_oid == null || g_id.Value == "\"\"" || g_s.Value == "\"\"" || oi_oid.Value == "\"\"") { Program.Logger.Error($"Login failed"); throw new Exception("Login failed"); } else { IsLoggedIn = true; Program.Logger.Info($"Login successful"); } }