public void SendVerifier(string method, string country, string phone, SendVerifierCallback callback) { sendVerifierQeury["idvType"] = method; sendVerifierQeury["MobileCountry"] = country; sendVerifierQeury["MobileNumber"] = phone; sendVerifierQeury["PhoneType"] = "MOBILE"; sendVerifierQeury["MobileCarrier"] = ""; var sendVerifierUrl = "https://accounts.google.com/b/0/IdvChallenge?idvContinueHandler=SERVICE&service=ah"; var cl = new WebClientWithCookies(); cl.UploadValuesAsync(new Uri(sendVerifierUrl), sendVerifierQeury); cl.UploadValuesCompleted += (s, o) => { var html = o.Error == null?Encoding.UTF8.GetString(o.Result) : ""; if (html.Contains("\"idvGivenAnswer\"")) { verifyQuery = initQuery(html); callback(true); } else { callback(false); } }; }
public void Verify(string verifier, VerifyCallback callback) { verifyQuery["idvGivenAnswer"] = verifier; var verifyUrl = "https://accounts.google.com/b/0/IdvVerify?idvContinueHandler=SERVICE&service=ah"; var cl = new WebClientWithCookies(); cl.UploadValuesAsync(new Uri(verifyUrl), verifyQuery); cl.UploadValuesCompleted += (s, o) => { var html = Encoding.UTF8.GetString(o.Result); callback(!html.Contains("\"idvGivenAnswer\"")); }; }
public void CheckAppIdAvailability(string id, CheckAppIdCallback callback) { var client = new WebClientWithCookies(); var url = "https://appengine.google.com/start/checkappid?app_id=" + HttpUtility.UrlEncode(id); client.DownloadStringAsync(new Uri(url)); client.DownloadStringCompleted += (sender, e) => { if (e.Error != null) { callback(false); } else { callback(!e.Result.Contains("invalid")); } }; }
public void Login(string email, string password, LoginCallback callback) { var client = new WebClientWithCookies(); var loginHomeUrl = "https://accounts.google.com/ServiceLogin?service=ah&passive=true&continue=https://appengine.google.com/_ah/conflogin%3Fcontinue%3Dhttps://appengine.google.com/start<mpl=ae"; var loginUrl = "https://accounts.google.com/ServiceLoginAuth"; var userRe = new Regex(@"id=""ae-userinfo"">[\s\S]+?<strong>\s*([^\s]+?@[^\s]+?)\s*</strong>"); client.DownloadStringAsync(new Uri(loginHomeUrl)); client.DownloadStringCompleted += (sender, e) => { if (e.Error != null) { callback(false, null); return; } var processHtml = new Action<string>((h) => { if (!userRe.IsMatch(h)) { callback(false, null); return; } int remaining; var remainingMatch = new Regex(@"(\d+) applications remaining").Match(h); if (remainingMatch.Success) { remaining = int.Parse(remainingMatch.Groups[1].Value); } else { remaining = 10; } var appIds = new List<string>(); var noneDeployedAppIds = new List<string>(); var idMatches = new Regex(@"<tr[\s\S]+?&app_id=s~(.+?)""[\s\S]*?</tr>").Matches(h); foreach (Match match in idMatches) { if (!match.Value.Contains("<strong>Disabled")) { var id = match.Groups[1].Value; appIds.Add(id); if (match.Value.Contains("None Deployed")) { noneDeployedAppIds.Add(id); } } } callback(true, new LoginCallbackData() { AppIds = appIds.ToArray(), NoneDeployedAppIds = noneDeployedAppIds.ToArray(), RemainingNumber = remaining }); }); var processLogin = new Action<string>((h) => { var query = initQuery(h); query["Email"] = email; query["Passwd"] = password; query["PersistentCookie"] = "yes"; var cl = new WebClientWithCookies(); cl.UploadValuesAsync(new Uri(loginUrl), query); cl.UploadValuesCompleted += (s, o) => { processHtml(o.Error == null ? Encoding.UTF8.GetString(o.Result) : ""); }; }); var html = e.Result; var userMatch = userRe.Match(html); if (userMatch.Success) { var user = userMatch.Groups[1].Value; if (user.ToLower() == email.ToLower()) { processHtml(html); } else { loginHomeUrl = "https://appengine.google.com/_ah/logout?continue=https://www.google.com/accounts/Logout%3Fcontinue%3Dhttps://appengine.google.com/_ah/logout%253Fcontinue%253Dhttps://appengine.google.com/start%26service%3Dah"; var cl = new WebClientWithCookies(); cl.DownloadStringAsync(new Uri(loginHomeUrl)); cl.DownloadStringCompleted += (ss, ee) => { if (ee.Error != null) { callback(false, null); } else { processLogin(ee.Result); } }; } } else { processLogin(html); } }; }
public void Verify(string verifier, VerifyCallback callback) { verifyQuery["idvGivenAnswer"] = verifier; var verifyUrl = "https://accounts.google.com/b/0/IdvVerify?idvContinueHandler=SERVICE&service=ah"; var cl = new WebClientWithCookies(); cl.UploadValuesAsync(new Uri(verifyUrl), verifyQuery); cl.UploadValuesCompleted += (s, o) => { var html = o.Error == null ? Encoding.UTF8.GetString(o.Result) : ""; callback(!html.Contains("\"idvGivenAnswer\"")); }; }
public void SendVerifier(string method, string country, string phone, SendVerifierCallback callback) { sendVerifierQeury["idvType"] = method; sendVerifierQeury["MobileCountry"] = country; sendVerifierQeury["MobileNumber"] = phone; sendVerifierQeury["PhoneType"] = "MOBILE"; sendVerifierQeury["MobileCarrier"] = ""; var sendVerifierUrl = "https://accounts.google.com/b/0/IdvChallenge?idvContinueHandler=SERVICE&service=ah"; var cl = new WebClientWithCookies(); cl.UploadValuesAsync(new Uri(sendVerifierUrl), sendVerifierQeury); cl.UploadValuesCompleted += (s, o) => { var html = o.Error == null ? Encoding.UTF8.GetString(o.Result) : ""; if (html.Contains("\"idvGivenAnswer\"")) { verifyQuery = initQuery(html); callback(true); } else { callback(false); } }; }
public void CreateApps(string prefix, int number, CreateAppsCallback callback) { var current = 0; var i = 0; NameValueCollection query = null; Action<bool, bool> next = null; next = new Action<bool, bool>((valid, retry) => { if (!retry) { current++; } if (valid) { i++; } if (i >= number) { callback(true, i, null); return; } var id = prefix + "-" + current; callback(false, i, id); CheckAppIdAvailability(id, (v) => { if (v) { query["app_id"] = id; query["title"] = "GoAgent Server " + current; query["tos_accept"] = "on"; var cl = new WebClientWithCookies(); cl.UploadValuesAsync(new Uri("https://appengine.google.com/start/createapp.do"), query); cl.UploadValuesCompleted += (sender, e) => { if (e.Error == null && Encoding.UTF8.GetString(e.Result).Contains("Application Registered Successfully")) { next(true, false); } else { next(true, true); } }; } else { next(false, false); } }); }); Action prefetch = null; prefetch = new Action(() => { var client = new WebClientWithCookies(); client.DownloadStringAsync(new Uri("https://appengine.google.com/start/createapp")); //client.DownloadStringAsync(new Uri("https://accounts.google.com/b/0/IdvChallenge?idvContinueHandler=SERVICE&service=ah")); client.DownloadStringCompleted += (sender, e) => { if (e.Error == null && e.Result.Contains("IdvPhoneType()")) { //var r = MessageBox.Show(resources["GaeBeforeVerifyMessage"] as string, resources["XWall"] as string, MessageBoxButton.OKCancel); //if (r == MessageBoxResult.OK) { // Process.Start("\"https://accounts.google.com/ServiceLogin?continue=https%3A%2F%2Faccounts.google.com%2Fb%2F0%2FIdvChallenge%3FidvContinueHandler%3DSERVICE%26service%3Dah\""); // r = MessageBox.Show(resources["GaeAfterVerifyMessage"] as string, resources["XWall"] as string, MessageBoxButton.OKCancel); // if (r == MessageBoxResult.OK) { // prefetch(); // } // else { // callback(false, 0, null, true); // } //} //else { // callback(false, 0, null, true); //} sendVerifierQeury = initQuery(e.Result); VerificationRequired(() => { prefetch(); }); } else { query = initQuery(e.Result); query["auth_config"] = "google"; next(false, false); } }; }); prefetch(); }
public void Login(string email, string password, LoginCallback callback) { var client = new WebClientWithCookies(); var loginHomeUrl = "https://accounts.google.com/ServiceLogin?service=ah&passive=true&continue=https://appengine.google.com/_ah/conflogin%3Fcontinue%3Dhttps://appengine.google.com/start<mpl=ae"; var loginUrl = "https://accounts.google.com/ServiceLoginAuth"; var userRe = new Regex(@"id=""ae-userinfo"">[\s\S]+?<strong>\s*([^\s]+?@[^\s]+?)\s*</strong>"); client.DownloadStringAsync(new Uri(loginHomeUrl)); client.DownloadStringCompleted += (sender, e) => { if (e.Error != null) { callback(false, null); return; } var processHtml = new Action <string>((h) => { if (!userRe.IsMatch(h)) { callback(false, null); return; } int remaining; var remainingMatch = new Regex(@"(\d+) applications remaining").Match(h); if (remainingMatch.Success) { remaining = int.Parse(remainingMatch.Groups[1].Value); } else { remaining = 10; } var appIds = new List <string>(); var noneDeployedAppIds = new List <string>(); var idMatches = new Regex(@"<tr[\s\S]+?&app_id=s~(.+?)""[\s\S]*?</tr>").Matches(h); foreach (Match match in idMatches) { if (!match.Value.Contains("<strong>Disabled")) { var id = match.Groups[1].Value; appIds.Add(id); if (match.Value.Contains("None Deployed")) { noneDeployedAppIds.Add(id); } } } callback(true, new LoginCallbackData() { AppIds = appIds.ToArray(), NoneDeployedAppIds = noneDeployedAppIds.ToArray(), RemainingNumber = remaining }); }); var processLogin = new Action <string>((h) => { var query = initQuery(h); query["Email"] = email; query["Passwd"] = password; query["PersistentCookie"] = "yes"; var cl = new WebClientWithCookies(); cl.UploadValuesAsync(new Uri(loginUrl), query); cl.UploadValuesCompleted += (s, o) => { processHtml(o.Error == null ? Encoding.UTF8.GetString(o.Result) : ""); }; }); var html = e.Result; var userMatch = userRe.Match(html); if (userMatch.Success) { var user = userMatch.Groups[1].Value; if (user.ToLower() == email.ToLower()) { processHtml(html); } else { loginHomeUrl = "https://appengine.google.com/_ah/logout?continue=https://www.google.com/accounts/Logout%3Fcontinue%3Dhttps://appengine.google.com/_ah/logout%253Fcontinue%253Dhttps://appengine.google.com/start%26service%3Dah"; var cl = new WebClientWithCookies(); cl.DownloadStringAsync(new Uri(loginHomeUrl)); cl.DownloadStringCompleted += (ss, ee) => { if (ee.Error != null) { callback(false, null); } else { processLogin(ee.Result); } }; } } else { processLogin(html); } }; }
public void CreateApps(string prefix, int number, CreateAppsCallback callback) { var current = 0; var i = 0; NameValueCollection query = null; Action <bool, bool> next = null; next = new Action <bool, bool>((valid, retry) => { if (!retry) { current++; } if (valid) { i++; } if (i >= number) { callback(true, i, null); return; } var id = prefix + "-" + current; callback(false, i, id); CheckAppIdAvailability(id, (v) => { if (v) { query["app_id"] = id; query["title"] = "GoAgent Server " + current; query["tos_accept"] = "on"; var cl = new WebClientWithCookies(); cl.UploadValuesAsync(new Uri("https://appengine.google.com/start/createapp.do"), query); cl.UploadValuesCompleted += (sender, e) => { if (e.Error == null && Encoding.UTF8.GetString(e.Result).Contains("Application Registered Successfully")) { next(true, false); } else { next(true, true); } }; } else { next(false, false); } }); }); Action prefetch = null; prefetch = new Action(() => { var client = new WebClientWithCookies(); client.DownloadStringAsync(new Uri("https://appengine.google.com/start/createapp")); //client.DownloadStringAsync(new Uri("https://accounts.google.com/b/0/IdvChallenge?idvContinueHandler=SERVICE&service=ah")); client.DownloadStringCompleted += (sender, e) => { if (e.Error == null && e.Result.Contains("IdvPhoneType()")) { //var r = MessageBox.Show(resources["GaeBeforeVerifyMessage"] as string, resources["XWall"] as string, MessageBoxButton.OKCancel); //if (r == MessageBoxResult.OK) { // Process.Start("\"https://accounts.google.com/ServiceLogin?continue=https%3A%2F%2Faccounts.google.com%2Fb%2F0%2FIdvChallenge%3FidvContinueHandler%3DSERVICE%26service%3Dah\""); // r = MessageBox.Show(resources["GaeAfterVerifyMessage"] as string, resources["XWall"] as string, MessageBoxButton.OKCancel); // if (r == MessageBoxResult.OK) { // prefetch(); // } // else { // callback(false, 0, null, true); // } //} //else { // callback(false, 0, null, true); //} sendVerifierQeury = initQuery(e.Result); VerificationRequired(() => { prefetch(); }); } else { query = initQuery(e.Result); query["auth_config"] = "google"; next(false, false); } }; }); prefetch(); }