private static void AuthorizeAppOAuth(DropboxServiceProvider dropboxServiceProvider) { // Authorization without callback url Console.Write("Getting request token..."); OAuthToken oauthToken = dropboxServiceProvider.OAuthOperations.FetchRequestTokenAsync(null, null).Result; Console.WriteLine("Done."); OAuth1Parameters parameters = new OAuth1Parameters(); string authenticateUrl = dropboxServiceProvider.OAuthOperations.BuildAuthorizeUrl( oauthToken.Value, parameters); Console.WriteLine("Redirect the user for authorization to {0}", authenticateUrl); Process.Start(authenticateUrl); Console.Write("Press [Enter] when authorization attempt has succeeded."); Console.ReadLine(); Console.Write("Getting access token..."); AuthorizedRequestToken requestToken = new AuthorizedRequestToken(oauthToken, null); OAuthToken oauthAccessToken = dropboxServiceProvider.OAuthOperations.ExchangeForAccessTokenAsync(requestToken, null).Result; Console.WriteLine("Done."); string[] oauthData = new string[] { oauthAccessToken.Value, oauthAccessToken.Secret }; File.WriteAllLines(OAuthTokenFileName, oauthData); }
public override String Ejecutar() { try { DropboxServiceProvider dropbocServiceProvider = new DropboxServiceProvider(DropboxAppKey, DropboxAppSecret, AccessLevel.Full); OAuthToken oauthToken = dropbocServiceProvider.OAuthOperations.FetchRequestTokenAsync(null, null).Result; Comandodrop.Token = oauthToken; OAuth1Parameters parameters = new OAuth1Parameters(); parameters.CallbackUrl = puerto + "/Presentacion/Vista/TokenizeUser.aspx"; string authenticateUrl = dropbocServiceProvider.OAuthOperations.BuildAuthorizeUrl(oauthToken.Value, parameters); ruta = authenticateUrl; if (log.IsInfoEnabled) { log.Info(puerto.ToString()); } return(ruta); } catch (AggregateException ae) { ae.Handle(ex => { if (ex is DropboxApiException) { Console.WriteLine(ex.Message); if (log.IsErrorEnabled) { log.Error(ex.Message, ex); } return(estado = false); } return(estado = false); }); return(ruta); } }
private void DropboxAuthStart() { OAuth1Parameters parameters = new OAuth1Parameters(); parameters.CallbackUrl = ConfigurationManager.AppSettings["DropboxCallback"] + "?dropboxcallback=1"; SaveSession(); Response.Redirect(AppCache.dropboxProvider.OAuthOperations.BuildAuthenticateUrl(AppCache.requestToken.Value, parameters)); }
public void Authenticate() { this.DropboxServiceProvider.OAuthOperations.FetchRequestTokenAsync(null, null, r => { this.requestOAuthToken = r.Response; OAuth1Parameters parameters = new OAuth1Parameters(); parameters.CallbackUrl = CallbackUrl; this.AuthenticateUri = new Uri(this.DropboxServiceProvider.OAuthOperations.BuildAuthenticateUrl(r.Response.Value, parameters)); }); }
// GET: /Dropbox/SignIn public ActionResult SignIn() { OAuthToken requestToken = dropboxProvider.OAuthOperations.FetchRequestTokenAsync(null, null).Result; Session["RequestToken"] = requestToken; OAuth1Parameters parameters = new OAuth1Parameters(); parameters.CallbackUrl = "http://localhost/Dropbox/Callback"; //parameters.Add("locale", System.Globalization.CultureInfo.CurrentUICulture.IetfLanguageTag); // for a localized version of the authorization website return(Redirect(dropboxProvider.OAuthOperations.BuildAuthenticateUrl(requestToken.Value, parameters))); }
private void AuthorizeAppOAuth(DropboxServiceProvider dropboxServiceProvider) { OAuthToken oauthToken = dropboxServiceProvider.OAuthOperations.FetchRequestTokenAsync(null, null).Result; OAuth1Parameters parameters = new OAuth1Parameters(); string authenticateUrl = dropboxServiceProvider.OAuthOperations.BuildAuthorizeUrl(oauthToken.Value, parameters); Process.Start(authenticateUrl); AuthorizedRequestToken requestToken = new AuthorizedRequestToken(oauthToken, null); OAuthToken oauthAccessToken = dropboxServiceProvider.OAuthOperations.ExchangeForAccessTokenAsync(requestToken, null).Result; string[] oauthData = new string[] { oauthAccessToken.Value, oauthAccessToken.Secret }; File.WriteAllLines(OAuthTokenFileName, oauthData); }
static void Main(string[] args) { try { DropboxServiceProvider dropboxServiceProvider = new DropboxServiceProvider(DropboxAppKey, DropboxAppSecret, AccessLevel.Full); #if NET_4_0 /* OAuth 1.0 'dance' */ // Authorization without callback url Console.Write("Getting request token..."); OAuthToken oauthToken = dropboxServiceProvider.OAuthOperations.FetchRequestTokenAsync(null, null).Result; Console.WriteLine("Done"); OAuth1Parameters parameters = new OAuth1Parameters(); //parameters.Add("locale", CultureInfo.CurrentUICulture.IetfLanguageTag); // for a localized version of the authorization website string authenticateUrl = dropboxServiceProvider.OAuthOperations.BuildAuthorizeUrl(oauthToken.Value, parameters); Console.WriteLine("Redirect user for authorization"); Process.Start(authenticateUrl); Console.Write("Press any key when authorization attempt has succeeded"); Console.ReadLine(); Console.Write("Getting access token..."); AuthorizedRequestToken requestToken = new AuthorizedRequestToken(oauthToken, null); OAuthToken oauthAccessToken = dropboxServiceProvider.OAuthOperations.ExchangeForAccessTokenAsync(requestToken, null).Result; Console.WriteLine("Done"); /* API */ IDropbox dropbox = dropboxServiceProvider.GetApi(oauthAccessToken.Value, oauthAccessToken.Secret); //dropbox.Locale = CultureInfo.CurrentUICulture.IetfLanguageTag; DropboxProfile profile = dropbox.GetUserProfileAsync().Result; Console.WriteLine("Hi " + profile.DisplayName + "!"); // Use step by step debugging, or not /* * Entry createFolderEntry = dropbox.CreateFolderAsync("Spring Social").Result; * Entry uploadFileEntry = dropbox.UploadFileAsync( * new AssemblyResource("assembly://Spring.ConsoleQuickStart/Spring.ConsoleQuickStart/File.txt"), * "/Spring Social/File.txt", true, null, CancellationToken.None).Result; * Entry copyEntry = dropbox.CopyAsync("Spring Social/File.txt", "Spring Social/File_copy.txt").Result; * Entry deleteEntry = dropbox.DeleteAsync("Spring Social/File.txt").Result; * Entry moveEntry = dropbox.MoveAsync("Spring Social/File_copy.txt", "Spring Social/File.txt").Result; * dropbox.DownloadFileAsync("Spring Social/File.txt") * .ContinueWith(task => * { * Console.WriteLine("File '{0}' downloaded ({1})", task.Result.Metadata.Path, task.Result.Metadata.Size); * // Save file to "C:\Spring Social.txt" * using (FileStream fileStream = new FileStream(@"C:\Spring Social.txt", FileMode.Create)) * { * fileStream.Write(task.Result.Content, 0, task.Result.Content.Length); * } * }); * Entry folderMetadata = dropbox.GetMetadataAsync("Spring Social").Result; * IList<Entry> revisionsEntries = dropbox.GetRevisionsAsync("Spring Social/File.txt").Result; * Entry restoreEntry = dropbox.RestoreAsync("Spring Social/File.txt", revisionsEntries[2].Revision).Result; * IList<Entry> searchResults = dropbox.SearchAsync("Spring Social/", ".txt").Result; * DropboxLink shareableLink = dropbox.GetShareableLinkAsync("Spring Social/File.txt").Result; * DropboxLink mediaLink = dropbox.GetMediaLinkAsync("Spring Social/File.txt").Result; * Entry uploadImageEntry = dropbox.UploadFileAsync( * new AssemblyResource("assembly://Spring.ConsoleQuickStart/Spring.ConsoleQuickStart/Image.png"), * "/Spring Social/Image.png", true, null, CancellationToken.None).Result; * dropbox.DownloadThumbnailAsync("Spring Social/Image.png", ThumbnailFormat.Png, ThumbnailSize.Medium) * .ContinueWith(task => * { * Console.WriteLine("Thumbnail '{0}' downloaded ({1})", task.Result.Metadata.Path, task.Result.Metadata.Size); * // Save file to "C:\Thumbnail_Medium.png" * using (FileStream fileStream = new FileStream(@"C:\Thumbnail_Medium.png", FileMode.Create)) * { * fileStream.Write(task.Result.Content, 0, task.Result.Content.Length); * } * }); */ } catch (AggregateException ae) { ae.Handle(ex => { if (ex is DropboxApiException) { Console.WriteLine(ex.Message); return(true); } return(false); }); } #else /* OAuth 1.0 'dance' */ // Authorization without callback url Console.Write("Getting request token..."); OAuthToken oauthToken = dropboxServiceProvider.OAuthOperations.FetchRequestToken(null, null); Console.WriteLine("Done"); OAuth1Parameters parameters = new OAuth1Parameters(); //parameters.Add("locale", CultureInfo.CurrentUICulture.IetfLanguageTag); // for a localized version of the authorization website string authenticateUrl = dropboxServiceProvider.OAuthOperations.BuildAuthorizeUrl(oauthToken.Value, parameters); Console.WriteLine("Redirect user for authorization"); Process.Start(authenticateUrl); Console.Write("Press any key when authorization attempt has succeeded"); Console.ReadLine(); Console.Write("Getting access token..."); AuthorizedRequestToken requestToken = new AuthorizedRequestToken(oauthToken, null); OAuthToken oauthAccessToken = dropboxServiceProvider.OAuthOperations.ExchangeForAccessToken(requestToken, null); Console.WriteLine("Done"); /* API */ IDropbox dropbox = dropboxServiceProvider.GetApi(oauthAccessToken.Value, oauthAccessToken.Secret); //dropbox.Locale = CultureInfo.CurrentUICulture.IetfLanguageTag; DropboxProfile profile = dropbox.GetUserProfile(); Console.WriteLine("Hi " + profile.DisplayName + "!"); // Use step by step debugging, or not /* * Entry createFolderEntry = dropbox.CreateFolder("Spring Social"); * Entry uploadFileEntry = dropbox.UploadFile( * new AssemblyResource("assembly://Spring.ConsoleQuickStart/Spring.ConsoleQuickStart/File.txt"), * "/Spring Social/File.txt", true, null); * Entry copyEntry = dropbox.Copy("Spring Social/File.txt", "Spring Social/File_copy.txt"); * Entry deleteEntry = dropbox.Delete("Spring Social/File.txt"); * Entry moveEntry = dropbox.Move("Spring Social/File_copy.txt", "Spring Social/File.txt"); * var fileCanceler = dropbox.DownloadFileAsync("Spring Social/File.txt", * r => * { * Console.WriteLine("File '{0}' downloaded ({1})", r.Response.Metadata.Path, r.Response.Metadata.Size); * // Save file to "C:\Spring Social.txt" * using (FileStream fileStream = new FileStream(@"C:\Spring Social.txt", FileMode.Create)) * { * fileStream.Write(r.Response.Content, 0, r.Response.Content.Length); * } * }); * Entry folderMetadata = dropbox.GetMetadata("Spring Social"); * IList<Entry> revisionsEntries = dropbox.GetRevisions("Spring Social/File.txt"); * Entry restoreEntry = dropbox.Restore("Spring Social/File.txt", revisionsEntries[2].Revision); * IList<Entry> searchResults = dropbox.Search("Spring Social/", ".txt"); * DropboxLink shareableLink = dropbox.GetShareableLink("Spring Social/File.txt"); * DropboxLink mediaLink = dropbox.GetMediaLink("Spring Social/File.txt"); * Entry uploadImageEntry = dropbox.UploadFile( * new AssemblyResource("assembly://Spring.ConsoleQuickStart/Spring.ConsoleQuickStart/Image.png"), * "/Spring Social/Image.png", true, null); * var thumbnailCanceler = dropbox.DownloadThumbnailAsync("Spring Social/Image.png", ThumbnailFormat.Png, ThumbnailSize.Medium, * r => * { * Console.WriteLine("Thumbnail '{0}' downloaded ({1})", r.Response.Metadata.Path, r.Response.Metadata.Size); * // Save file to "C:\Thumbnail_Medium.png" * using (FileStream fileStream = new FileStream(@"C:\Thumbnail_Medium.png", FileMode.Create)) * { * fileStream.Write(r.Response.Content, 0, r.Response.Content.Length); * } * }); */ }
private void Worker() { Interface.Oxide.LogInfo("[DropBox] Initialized"); _Settings = _DataFileSystem.ReadObject <Settings>(Path.Combine(_ConfigDirectory, "DropBox")); if (_Settings.FileList == null) { _Settings = new Settings(); _Settings.BackupOxideConfig = true; _Settings.BackupOxideData = true; _Settings.BackupOxideLang = true; _Settings.BackupOxideLogs = true; _Settings.BackupOxidePlugins = true; _Settings.FileList = new List <string>(); _Settings.UserToken = ""; _Settings.UserSecret = ""; _Settings.BackupName = "Oxide DropBox Extension"; _Settings.BackupInterval = 3600; _Settings.DropboxApi = new Dictionary <string, string>(); _Settings.DropboxApi.Add("DropboxAppKey", ""); _Settings.DropboxApi.Add("DropboxAppSecret", ""); _DataFileSystem.WriteObject <Settings>(Path.Combine(_ConfigDirectory, "DropBox"), _Settings); } if (_Settings.BackupInterval < 3600) { Interface.Oxide.LogError("[DropBox] You can't set backup interval lower than 1 hour."); _Settings.BackupInterval = 3600; _DataFileSystem.WriteObject <Settings>(Path.Combine(_ConfigDirectory, "DropBox"), _Settings); } if ((string.IsNullOrEmpty(_Settings.DropboxApi["DropboxAppKey"])) || (string.IsNullOrEmpty(_Settings.DropboxApi["DropboxAppSecret"]))) { _running = false; Interface.Oxide.LogWarning("[DropBox] To able to use DropBox Extension you need to set DropboxAppKey and DropboxAppSecret in config file."); } if (_running) { DropboxServiceProvider dropboxServiceProvider = new DropboxServiceProvider(_Settings.DropboxApi["DropboxAppKey"], _Settings.DropboxApi["DropboxAppSecret"], AccessLevel.Full); OAuthToken oauthAccessToken = null; bool Authorized = false; IDropbox dropbox = null; do { if ((_running) && (string.IsNullOrEmpty(_Settings.UserToken) || string.IsNullOrEmpty(_Settings.UserSecret))) { Interface.Oxide.LogInfo("[DropBox] Getting request token..."); OAuthToken oauthToken = dropboxServiceProvider.OAuthOperations.FetchRequestToken(null, null); Interface.Oxide.LogInfo("[DropBox] Done"); OAuth1Parameters parameters = new OAuth1Parameters(); string authenticateUrl = dropboxServiceProvider.OAuthOperations.BuildAuthenticateUrl(oauthToken.Value, parameters); Interface.Oxide.LogInfo("[DropBox] Redirect user for authorization"); Interface.Oxide.LogInfo("[DropBox] {0}", authenticateUrl); while ((_running) && (Authorized == false)) { try { AuthorizedRequestToken requestToken = new AuthorizedRequestToken(oauthToken, null); oauthAccessToken = dropboxServiceProvider.OAuthOperations.ExchangeForAccessToken(requestToken, null); Authorized = true; _Settings.UserToken = oauthAccessToken.Value; _Settings.UserSecret = oauthAccessToken.Secret; _DataFileSystem.WriteObject <Settings>(Path.Combine(_ConfigDirectory, "DropBox"), _Settings); } catch { Thread.Sleep(5000); } } } else if (_running) { oauthAccessToken = new OAuthToken(_Settings.UserToken, _Settings.UserSecret); } if (_running) { try { Interface.Oxide.LogInfo("[DropBox] Authorizing"); dropbox = dropboxServiceProvider.GetApi(oauthAccessToken.Value, oauthAccessToken.Secret); Interface.Oxide.LogInfo("[DropBox] Authorization Succeed"); Authorized = true; } catch { Interface.Oxide.LogWarning("[DropBox] Authorization Failed"); _Settings.UserToken = ""; _Settings.UserSecret = ""; _DataFileSystem.WriteObject <Settings>(Path.Combine(_ConfigDirectory, "DropBox"), _Settings); Authorized = false; } } } while ((_running) && (Authorized == false)); if ((_running) && (dropbox != null) && (Authorized == true)) { DropboxProfile profile = dropbox.GetUserProfile(); Interface.Oxide.LogInfo("[DropBox] Current Dropbox User : {0}({1})", profile.DisplayName, profile.Email); DateTime NextUpdate = DateTime.Now.AddSeconds(60); Interface.Oxide.LogInfo("[DropBox] First Backup : {0}", NextUpdate.ToString()); while (_running) { if (DateTime.Now < NextUpdate) { Thread.Sleep(1000); } else { string BackUpRoot = Path.Combine(Interface.Oxide.RootDirectory, "OxideExtBackup"); string OxideBackUpRoot = Path.Combine(BackUpRoot, "Oxide"); string FileBackUpRoot = Path.Combine(BackUpRoot, "Files"); Directory.CreateDirectory(BackUpRoot); DirectoryInfo OxideExtBackup = new DirectoryInfo(BackUpRoot); foreach (FileInfo file in OxideExtBackup.GetFiles()) { file.Delete(); } foreach (DirectoryInfo subDirectory in OxideExtBackup.GetDirectories()) { subDirectory.Delete(true); } Directory.CreateDirectory(OxideBackUpRoot); Directory.CreateDirectory(FileBackUpRoot); if (_Settings.BackupOxideConfig) { DirectoryCopy(Interface.Oxide.ConfigDirectory, Path.Combine(OxideBackUpRoot, "config"), true); } if (_Settings.BackupOxideData) { DirectoryCopy(Interface.Oxide.DataDirectory, Path.Combine(OxideBackUpRoot, "data"), true); } if (_Settings.BackupOxideLang) { DirectoryCopy(Interface.Oxide.LangDirectory, Path.Combine(OxideBackUpRoot, "lang"), true); } if (_Settings.BackupOxideLogs) { DirectoryCopy(Interface.Oxide.LogDirectory, Path.Combine(OxideBackUpRoot, "logs"), true); } if (_Settings.BackupOxidePlugins) { DirectoryCopy(Interface.Oxide.PluginDirectory, Path.Combine(OxideBackUpRoot, "plugins"), true); } foreach (string Current in _Settings.FileList) { if (!string.IsNullOrEmpty(Current)) { string CurrentPath = Path.GetFullPath(Path.Combine(Interface.Oxide.RootDirectory, Current)); if (!CurrentPath.StartsWith(Interface.Oxide.RootDirectory, StringComparison.Ordinal)) { Interface.Oxide.LogError("[DropBox] You may only access game releated directories..."); } else if ((File.GetAttributes(CurrentPath) & FileAttributes.Directory) == FileAttributes.Directory) { if (CurrentPath != Interface.Oxide.RootDirectory) { DirectoryCopy(CurrentPath, Path.Combine(FileBackUpRoot, new DirectoryInfo(CurrentPath).Name), true); } } else { File.Copy(CurrentPath, Path.Combine(FileBackUpRoot, new FileInfo(CurrentPath).Name)); } } } string FileName = string.Format("{0}.{1}.{2}.{3}.{4}.{5}.zip", DateTime.UtcNow.Year, DateTime.UtcNow.Month, DateTime.UtcNow.Day, DateTime.UtcNow.Hour, DateTime.UtcNow.Minute, DateTime.UtcNow.Second); FileStream fsOut = File.Create(Path.Combine(Interface.Oxide.RootDirectory, FileName)); ZipOutputStream zipStream = new ZipOutputStream(fsOut); zipStream.SetLevel(3); string folderName = Path.Combine(Interface.Oxide.RootDirectory, "OxideExtBackup"); int folderOffset = folderName.Length + (folderName.EndsWith("\\") ? 0 : 1); CompressFolder(folderName, zipStream, folderOffset); zipStream.IsStreamOwner = true; zipStream.Close(); Interface.Oxide.LogInfo("[DropBox] Uploading..."); Entry uploadFileEntry = dropbox.UploadFile(new FileResource(Path.Combine(Interface.Oxide.RootDirectory, FileName)), string.Format("/{0}/{1}", _Settings.BackupName, FileName), true, null); Directory.Delete(folderName, true); File.Delete(Path.Combine(Interface.Oxide.RootDirectory, FileName)); NextUpdate = NextUpdate.AddSeconds(_Settings.BackupInterval); Interface.Oxide.LogInfo("[DropBox] Uploading Complated.Next Backup : {0}", NextUpdate.ToString()); } } } } }