public static void ExportDocList(string outFolder, string username, string password) { GDataCredentials credentials = new GDataCredentials(username, password); RequestSettings settings = new RequestSettings("GDocBackup", credentials); settings.AutoPaging = true; settings.PageSize = 100; DocumentsRequest request = new DocumentsRequest(settings); Feed<Document> feed = request.GetEverything(); List<Document> docs = new List<Document>(); foreach (Document entry in feed.Entries) docs.Add(entry); using (StreamWriter outFile = new StreamWriter(Path.Combine(outFolder, "doclist.txt"), false), outFile2 = new StreamWriter(Path.Combine(outFolder, "doclistdetails.txt"), false)) { foreach (Document doc in docs) { string s = doc.Title + "\t" + doc.ResourceId; outFile.WriteLine(s); outFile2.WriteLine(s); foreach (string pf in doc.ParentFolders) outFile2.WriteLine("\t\t\t" + pf); } outFile.Close(); outFile2.Close(); } }
/// <summary>sets up the correct credentials for this call, pending /// security scheme</summary> protected override void EnsureCredentials() { Tracing.Assert(this.Request != null, "We should have a webrequest now"); if (this.Request == null) { return; } // if the token is NULL, we need to get a token. if (this.factory.GAuthToken == null) { // we will take the standard credentials for that GDataCredentials gc = this.Credentials; Tracing.TraceMsg(gc == null ? "No Network credentials set" : "Network credentials found"); if (gc != null) { // only now we have something to do... this.factory.GAuthToken = QueryAuthToken(gc); } } if (this.factory.GAuthToken != null && this.factory.GAuthToken.Length > 0) { // Tracing.Assert(this.factory.GAuthToken != null, "We should have a token now"); Tracing.TraceMsg("Using auth token: " + this.factory.GAuthToken); string strHeader = GoogleAuthentication.Header + this.factory.GAuthToken; this.Request.Headers.Add(strHeader); } }
/// <summary> /// a constructor for client login use cases /// </summary> /// <param name="applicationName">The name of the application</param> /// <param name="credentials">the user credentials</param> /// <returns></returns> public ClientLoginAuthenticator( string applicationName, string serviceName, GDataCredentials credentials) : this(applicationName, serviceName, credentials, null) { }
/// <summary>goes to the Google auth service, and gets a new auth token</summary> /// <returns>the auth token, or NULL if none received</returns> internal string QueryAuthToken(GDataCredentials gc) { Uri authHandler = null; // need to copy this to a new object to avoid that people mix and match // the old (factory) and the new (requestsettings) and get screwed. So // copy the settings from the gc passed in and mix with the settings from the factory GDataCredentials gdc = new GDataCredentials(gc.Username, gc.getPassword()); gdc.CaptchaToken = this.factory.CaptchaToken; gdc.CaptchaAnswer = this.factory.CaptchaAnswer; gdc.AccountType = gc.AccountType; try { authHandler = new Uri(this.factory.Handler); } catch { throw new GDataRequestException("Invalid authentication handler URI given"); } return Utilities.QueryClientLoginToken( gdc, this.factory.Service, this.factory.ApplicationName, this.factory.KeepAlive, this.factory.Proxy, authHandler); }
public static void Exec(string[] args) { Console.WriteLine("*** GetDocList ***"); Console.WriteLine("--- START ---"); string username = args[1]; string password = args[2]; GDataCredentials credentials = new GDataCredentials(username, password); RequestSettings settings = new RequestSettings("GDocBackup", credentials); settings.AutoPaging = true; settings.PageSize = 100; DocumentsRequest request = new DocumentsRequest(settings); Feed<Document> feed = request.GetEverything(); List<Document> docs = new List<Document>(); foreach (Document entry in feed.Entries) docs.Add(entry); StreamWriter outFile = new StreamWriter("doclist.txt", false); StreamWriter outFile2 = new StreamWriter("doclistdetails.txt", false); foreach (Document doc in docs) { string s = doc.Title + "\t" + doc.ResourceId; Console.WriteLine(s); outFile.WriteLine(s); outFile2.WriteLine(s); foreach (string pf in doc.ParentFolders) outFile2.WriteLine("\t\t\t" + pf); } outFile.Close(); outFile2.Close(); Console.WriteLine("--- END ---"); }
/// <summary>goes to the Google auth service, and gets a new auth token</summary> /// <returns>the auth token, or NULL if none received</returns> public static string QueryClientLoginToken(GDataCredentials gc, string serviceName, string applicationName, bool fUseKeepAlive, Uri clientLoginHandler) { return(QueryClientLoginToken(gc, serviceName, applicationName, fUseKeepAlive, null, clientLoginHandler)); }
public void UsernameTest() { string username = "******"; // TODO: Initialize to an appropriate value string password = "******"; // TODO: Initialize to an appropriate value GDataCredentials target = new GDataCredentials(username, password); // TODO: Initialize to an appropriate value string expected = "TestValue"; string actual; target.Username = expected; actual = target.Username; Assert.AreEqual(expected, actual); }
/// <summary> /// a constructor for client login use cases /// </summary> /// <param name="applicationName">The name of the application</param> /// <param name="credentials">the user credentials</param> /// <returns></returns> public ClientLoginAuthenticator(string applicationName, string serviceName, GDataCredentials credentials, Uri clientLoginHandler) : base(applicationName) { this.credentials = credentials; this.serviceName = serviceName; this.loginHandler = clientLoginHandler == null ? new Uri(GoogleAuthentication.UriHandler) : clientLoginHandler; }
private void GetDocListExec() { WriteMessage("*** GetDocList ***"); WriteMessage("--- START ---"); try { string username = tbUserName.Text; ; string password = tbPassword.Text; GDataCredentials credentials = new GDataCredentials(username, password); RequestSettings settings = new RequestSettings("GDocBackup", credentials); settings.AutoPaging = true; settings.PageSize = 100; DocumentsRequest request = new DocumentsRequest(settings); Feed<Document> feed = request.GetEverything(); List<Document> docs = new List<Document>(); foreach (Document entry in feed.Entries) docs.Add(entry); StreamWriter outFile = new StreamWriter("doclist.txt", false); StreamWriter outFile2 = new StreamWriter("doclistdetails.txt", false); WriteMessage("Exporting document list. Please wait..."); foreach (Document doc in docs) { string s = doc.Title + "\t" + doc.ResourceId; //WriteMessage(s); outFile.WriteLine(s); outFile2.WriteLine(s); foreach (string pf in doc.ParentFolders) outFile2.WriteLine("\t\t\t" + pf); } WriteMessage("Created file: doclist.txt"); WriteMessage("Created file: doclistdetails.txt"); outFile.Close(); outFile2.Close(); } catch (Exception ex) { WriteMessage("EXCEPTION: " + ex.ToString()); } WriteMessage("--- END ---"); }
///////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// /// <summary>Get's an authentication token for the current credentials</summary> ////////////////////////////////////////////////////////////////////// public string QueryAuthToken(GDataCredentials gc) { GDataGAuthRequest request = new GDataGAuthRequest(GDataRequestType.Query, null, this); return request.QueryAuthToken(gc); }
///////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// /// <summary>goes to the Google auth service, and gets a new auth token</summary> /// <returns>the auth token, or NULL if none received</returns> ////////////////////////////////////////////////////////////////////// internal string QueryAuthToken(GDataCredentials gc) { Tracing.Assert(gc != null, "Do not call QueryAuthToken with no network credentials"); if (gc == null) { throw new System.ArgumentNullException("nc", "No credentials supplied"); } // Create a new request to the authentication URL. Uri authHandler = null; try { authHandler = new Uri(this.factory.Handler); } catch { throw new GDataRequestException("Invalid authentication handler URI given"); } WebRequest authRequest = WebRequest.Create(authHandler); string accountType = GoogleAuthentication.AccountType; if (this.factory.AccountType != null) { accountType += this.factory.AccountType; } else { accountType += GoogleAuthentication.AccountTypeDefault; } if (this.factory.Proxy != null) { authRequest.Proxy = this.factory.Proxy; } HttpWebRequest web = authRequest as HttpWebRequest; if (web != null) { web.KeepAlive = this.factory.KeepAlive; } WebResponse authResponse = null; string authToken = null; try { authRequest.ContentType = HttpFormPost.Encoding; authRequest.Method = HttpMethods.Post; ASCIIEncoding encoder = new ASCIIEncoding(); string user = gc.Username == null ? "" : gc.Username; string pwd = gc.getPassword() == null ? "" : gc.getPassword(); // now enter the data in the stream string postData = GoogleAuthentication.Email + "=" + Utilities.UriEncodeUnsafe(user) + "&"; postData += GoogleAuthentication.Password + "=" + Utilities.UriEncodeUnsafe(pwd) + "&"; postData += GoogleAuthentication.Source + "=" + Utilities.UriEncodeUnsafe(this.factory.ApplicationName) + "&"; postData += GoogleAuthentication.Service + "=" + Utilities.UriEncodeUnsafe(this.factory.Service) + "&"; if (this.factory.CaptchaAnswer != null) { postData += GoogleAuthentication.CaptchaAnswer + "=" + Utilities.UriEncodeUnsafe(this.factory.CaptchaAnswer) + "&"; } if (this.factory.CaptchaToken != null) { postData += GoogleAuthentication.CaptchaToken + "=" + Utilities.UriEncodeUnsafe(this.factory.CaptchaToken) + "&"; } postData += accountType; byte[] encodedData = encoder.GetBytes(postData); authRequest.ContentLength = encodedData.Length; Stream requestStream = authRequest.GetRequestStream() ; requestStream.Write(encodedData, 0, encodedData.Length); requestStream.Close(); authResponse = authRequest.GetResponse(); } catch (WebException e) { Tracing.TraceMsg("QueryAuthtoken failed " + e.Status + " " + e.Message); authResponse = e.Response; } HttpWebResponse response = authResponse as HttpWebResponse; if (response != null) { // check the content type, it must be text if (!response.ContentType.StartsWith(HttpFormPost.ReturnContentType)) { throw new GDataRequestException("Execution of authentication request returned unexpected content type: " + response.ContentType, response); } TokenCollection tokens = Utilities.ParseStreamInTokenCollection(response.GetResponseStream()); authToken = Utilities.FindToken(tokens, GoogleAuthentication.AuthToken); if (authToken == null) { throw getAuthException(tokens, response); } // failsafe. if getAuthException did not catch an error... int code= (int)response.StatusCode; if (code != 200) { throw new GDataRequestException("Execution of authentication request returned unexpected result: " +code, response); } } Tracing.Assert(authToken != null, "did not find an auth token in QueryAuthToken"); if (authResponse != null) { authResponse.Close(); } return authToken; }
/// <summary> /// a constructor for client login use cases /// </summary> /// <param name="applicationName">The name of the application</param> /// <param name="credentials">the user credentials</param> /// <returns></returns> public ClientLoginAuthenticator(string applicationName, string serviceName, GDataCredentials credentials, Uri clientLoginHandler) : base(applicationName) { this.credentials = credentials; this.serviceName = serviceName; this.loginHandler = clientLoginHandler == null ? new Uri(GoogleAuthentication.UriHandler) : clientLoginHandler; }
public void CredentialsTest() { Service target = new Service(); // TODO: Initialize to an appropriate value GDataCredentials expected = new GDataCredentials("test", "pwd"); GDataCredentials actual; target.Credentials = expected; actual = target.Credentials; Assert.AreEqual(expected, actual); }
///////////////////////////////////////////////////////////////////////////// /// <summary> /// Sets the credentials of the user to authenticate requests /// to the server. /// </summary> /// <param name="username"></param> /// <param name="password"></param> public void setUserCredentials(String username, String password) { this.Credentials = new GDataCredentials(username, password); }
/// <summary> /// a constructor for client login use cases /// </summary> /// <param name="applicationName">The name of the application</param> /// <param name="credentials">the user credentials</param> /// <returns></returns> public ClientLoginAuthenticator(string applicationName, string serviceName, GDataCredentials credentials) : this(applicationName, serviceName, credentials, null) { }
private void ss() { GDataCredentials credentials = new GDataCredentials("*****@*****.**", "198ytdblbvrfpa$$w0rd"); RequestSettings settings = new RequestSettings("Testing", credentials); settings.AutoPaging = true; settings.PageSize = 100; DocumentsRequest documentsRequest = new DocumentsRequest(settings); Feed<Document> documentFeed = documentsRequest.GetDocuments(); Document doc = new Document(); foreach (Document document in documentFeed.Entries) { } documentsRequest.CreateDocument(new Document()); }
/// <summary>Gets an authentication token for the current credentials</summary> public string QueryAuthToken(GDataCredentials gc) { GDataGAuthRequest request = new GDataGAuthRequest(GDataRequestType.Query, null, this); return request.QueryAuthToken(gc); }
private void Cancel_Click(object sender, System.EventArgs e) { this.credentials = null; this.Close(); }
private void Login_Click(object sender, System.EventArgs e) { try { this.credentials = new GDataCredentials(this.Username.Text, this.Password.Text); this.DialogResult = DialogResult.OK; this.Close(); } catch (AuthenticationException a) { MessageBox.Show(a.Message); } }
private void Login_Click(object sender, System.EventArgs e) { this.credentials = new GDataCredentials(this.Username.Text, this.Password.Text); this.Close(); }
public static void Main (string[] args) { // TODO: Put string in a config file. ServicePointManager.ServerCertificateValidationCallback = Validator; const string applicationName = "lfont-GData.Synchronizer.Console-1"; const string email = "<A valid Google Account email>"; const string password = "******"; GDataCredentials gDataCredentials = new GDataCredentials(email, password); NetworkCredential networkCredential = new NetworkCredential(email, password); using (DocumentsWatcher documentsWatcher = new DocumentsWatcher(applicationName, gDataCredentials)) using (PicasaWatcher picasaWatcher = new PicasaWatcher(applicationName, gDataCredentials)) { TaskHistoryRepository historyRepository = new TaskHistoryRepository(); #region Documents CopyTask documentCopyTask = new CopyTask("Output".Combine("Documents", "CopyTask")) { HisotoryRepository = historyRepository, Prerequisites = f => true }; EmailTask documentEmailTask = new EmailTask(networkCredential, email) { HisotoryRepository = historyRepository, Prerequisites = f => true }; DocumentDownloadTask documentDownloadTask = new DocumentDownloadTask(documentsWatcher.Request) { Parallelize = true, Prerequisites = e => true, Tasks = { documentCopyTask, documentEmailTask } }; documentsWatcher.Tasks.Add(documentDownloadTask); documentsWatcher.WatchInterval = TimeSpan.FromMinutes(30); Logger.Info("Starting Documents watcher."); documentsWatcher.StartWatch (documentsWatcher.RetrieveAllDocuments); #endregion #region Picasa CopyTask picasaCopyTask = new CopyTask("Output".Combine("Picasa", "CopyTask")) { HisotoryRepository = historyRepository, Prerequisites = f => true }; EmailTask picasaEmailTask = new EmailTask(networkCredential, email) { HisotoryRepository = historyRepository, Prerequisites = f => true }; PicasaDownloadTask picasaDownloadTask = new PicasaDownloadTask(picasaWatcher.Request) { Parallelize = true, Prerequisites = e => true, Tasks = { picasaCopyTask, picasaEmailTask } }; picasaWatcher.Tasks.Add(picasaDownloadTask); picasaWatcher.WatchInterval = TimeSpan.FromMinutes(5); Logger.Info("Starting Picasa watcher."); picasaWatcher.StartWatch(picasaWatcher.RetrieveAllPhotos); #endregion System.Console.ReadLine(); } Logger.Info("All watchers have stopped successfuly."); System.Console.ReadLine(); }
public void NetworkCredentialTest() { string username = "******"; // TODO: Initialize to an appropriate value string password = "******"; // TODO: Initialize to an appropriate value GDataCredentials target = new GDataCredentials(username, password); // TODO: Initialize to an appropriate value ICredentials actual; actual = target.NetworkCredential; Assert.IsNotNull(actual); }
///////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// /// <summary>goes to the Google auth service, and gets a new auth token</summary> /// <returns>the auth token, or NULL if none received</returns> ////////////////////////////////////////////////////////////////////// internal string QueryAuthToken(GDataCredentials gc) { Uri authHandler = null; // need to copy this to a new object to avoid that people mix and match // the old (factory) and the new (requestsettings) and get screwed. So // copy the settings from the gc passed in and mix with the settings from the factory GDataCredentials gdc = new GDataCredentials(gc.Username, gc.getPassword()); gdc.CaptchaToken = this.factory.CaptchaToken; gdc.CaptchaAnswer = this.factory.CaptchaAnswer; gdc.AccountType = this.factory.AccountType; try { authHandler = new Uri(this.factory.Handler); } catch { throw new GDataRequestException("Invalid authentication handler URI given"); } return Utilities.QueryClientLoginToken(gdc, this.factory.Service, this.factory.ApplicationName, this.factory.KeepAlive, authHandler); }
/// <summary>goes to the Google auth service, and gets a new auth token</summary> /// <returns>the auth token, or NULL if none received</returns> public static string QueryClientLoginToken(GDataCredentials gc, string serviceName, string applicationName, bool fUseKeepAlive, IWebProxy proxyServer, Uri clientLoginHandler) { Tracing.Assert(gc != null, "Do not call QueryAuthToken with no network credentials"); if (gc == null) { throw new System.ArgumentNullException("nc", "No credentials supplied"); } HttpWebRequest authRequest = WebRequest.Create(clientLoginHandler) as HttpWebRequest; authRequest.KeepAlive = fUseKeepAlive; if (proxyServer != null) { authRequest.Proxy = proxyServer; } string accountType = GoogleAuthentication.AccountType; if (!String.IsNullOrEmpty(gc.AccountType)) { accountType += gc.AccountType; } else { accountType += GoogleAuthentication.AccountTypeDefault; } WebResponse authResponse = null; HttpWebResponse response = null; string authToken = null; try { authRequest.ContentType = HttpFormPost.Encoding; authRequest.Method = HttpMethods.Post; ASCIIEncoding encoder = new ASCIIEncoding(); string user = gc.Username == null ? "" : gc.Username; string pwd = gc.getPassword() == null ? "" : gc.getPassword(); // now enter the data in the stream string postData = GoogleAuthentication.Email + "=" + Utilities.UriEncodeUnsafe(user) + "&"; postData += GoogleAuthentication.Password + "=" + Utilities.UriEncodeUnsafe(pwd) + "&"; postData += GoogleAuthentication.Source + "=" + Utilities.UriEncodeUnsafe(applicationName) + "&"; postData += GoogleAuthentication.Service + "=" + Utilities.UriEncodeUnsafe(serviceName) + "&"; if (gc.CaptchaAnswer != null) { postData += GoogleAuthentication.CaptchaAnswer + "=" + Utilities.UriEncodeUnsafe(gc.CaptchaAnswer) + "&"; } if (gc.CaptchaToken != null) { postData += GoogleAuthentication.CaptchaToken + "=" + Utilities.UriEncodeUnsafe(gc.CaptchaToken) + "&"; } postData += accountType; byte[] encodedData = encoder.GetBytes(postData); authRequest.ContentLength = encodedData.Length; Stream requestStream = authRequest.GetRequestStream(); requestStream.Write(encodedData, 0, encodedData.Length); requestStream.Close(); authResponse = authRequest.GetResponse(); response = authResponse as HttpWebResponse; } catch (WebException e) { response = e.Response as HttpWebResponse; if (response == null) { Tracing.TraceMsg("QueryAuthtoken failed " + e.Status + " " + e.Message); throw; } } if (response != null) { // check the content type, it must be text if (!response.ContentType.StartsWith(HttpFormPost.ReturnContentType)) { throw new GDataRequestException("Execution of authentication request returned unexpected content type: " + response.ContentType, response); } TokenCollection tokens = Utilities.ParseStreamInTokenCollection(response.GetResponseStream()); authToken = Utilities.FindToken(tokens, GoogleAuthentication.AuthToken); if (authToken == null) { throw Utilities.getAuthException(tokens, response); } // failsafe. if getAuthException did not catch an error... int code = (int)response.StatusCode; if (code != 200) { throw new GDataRequestException("Execution of authentication request returned unexpected result: " + code, response); } } Tracing.Assert(authToken != null, "did not find an auth token in QueryAuthToken"); if (authResponse != null) { authResponse.Close(); } return(authToken); }
/// <summary> /// Sets the credentials of the user to authenticate requests /// to the server. /// </summary> /// <param name="username"></param> /// <param name="password"></param> public void setUserCredentials(String username, String password) { this.Credentials = new GDataCredentials(username, password); }
private void LoadAppSettings() { // Get the AppSettings collection. NameValueCollection appSettings = ConfigurationManager.AppSettings; if (appSettings[YouTubeUploader.CONFIG_DEVKEY] != null) { this.developerKey = appSettings[YouTubeUploader.CONFIG_DEVKEY]; } else { this.developerKey = YouTubeUploader.DeveloperKeyDefault; } if (String.IsNullOrEmpty(this.developerKey)) { MessageBox.Show("You need to enter a developer key in the source code. Look for DeveloperKeyDefault and paste your key in"); this.Close(); } if (appSettings[YouTubeUploader.CONFIG_MAXTHREADS] != null) { this.MaxQueue.Value = Decimal.Parse(appSettings[YouTubeUploader.CONFIG_MAXTHREADS]); } else { this.MaxQueue.Value = 3; } if (appSettings[YouTubeUploader.CONFIG_RETRYCOUNT] != null) { this.automaticRetries.Value = Decimal.Parse(appSettings[YouTubeUploader.CONFIG_RETRYCOUNT]); } else { this.automaticRetries.Value = 10; } if (appSettings[YouTubeUploader.CONFIG_CHUNKSIZE] != null) { this.ChunkSize.Value = Decimal.Parse(appSettings[YouTubeUploader.CONFIG_CHUNKSIZE]); } else { this.ChunkSize.Value = 25; } this.csvFileName = appSettings[YouTubeUploader.CONFIG_CSVFILE]; this.outputFileName = appSettings[YouTubeUploader.CONFIG_OUTPUTFILE]; if (appSettings[YouTubeUploader.CONFIG_USERNAME] != null) { this.credentials = new GDataCredentials(appSettings[YouTubeUploader.CONFIG_USERNAME], appSettings[YouTubeUploader.CONFIG_PASSWORD]); } this.youtubeAccount = appSettings[YouTubeUploader.CONFIG_YTACCOUNT]; }