public void Test_CanBuildAutorizeUrl() { var authorizeUrl = _client.BuildAuthorizeUrl(new DropNet.Models.UserLogin { Secret = TestVariables.Secret, Token = TestVariables.Token }); Assert.IsNotNull(authorizeUrl); }
public string AskForRegistrationUrl(UserProfileInfo user, string redirectUrl, out int tempCredentialId) { var _client = new DropNetClient(MogConstants.DROPBOX_KEY, MogConstants.DROPBOX_SECRET); UserLogin login = _client.GetToken(); // UserLogin login = _client.GetAccessToken(); var url = _client.BuildAuthorizeUrl(login, redirectUrl); var query = repoAuthCredential.GetByUserId(user.Id); List <AuthCredential> existingCredentials = null; if (query != null) {//TODO : gerer le cas des accounts multiples existingCredentials = query.Where(a => a.CloudService == CloudStorageServices.Dropbox).ToList(); foreach (var credential in existingCredentials) { repoAuthCredential.Delete(credential); } } AuthCredential newCredential = new AuthCredential(); newCredential.Token = login.Token; newCredential.Secret = login.Secret; newCredential.UserId = user.Id; newCredential.CloudService = CloudStorageServices.Dropbox; this.repoAuthCredential.Create(newCredential); tempCredentialId = newCredential.Id; return(url); }
public static void Main() { var client = new DropNetClient(DropboxAppKey, DropboxAppSecret); var token = client.GetToken(); var url = client.BuildAuthorizeUrl(); Console.WriteLine("COPY?PASTE Link: {0}", url); Console.WriteLine("Press enter when clicked allow"); Process.Start(@"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe", url); Console.ReadLine(); var accessToken = client.GetAccessToken(); client.UseSandbox = true; var metaData = client.CreateFolder("NewUpload" + DateTime.Now.ToString()); string[] dir = Directory.GetFiles("../../images/", "*.JPG"); foreach (var item in dir) { Console.WriteLine("Reading file....."); FileStream stream = File.Open(item, FileMode.Open); var bytes = new byte[stream.Length]; stream.Read(bytes, 0, (int)stream.Length); Console.WriteLine(bytes.Length + " bytes uploading..."); client.UploadFile("/" + metaData.Name.ToString(), item.Substring(6), bytes); Console.WriteLine("{0} uploaded!", item); stream.Close(); } Console.WriteLine("Job Done!"); var picUrl = client.GetShare(metaData.Path); Process.Start(@"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe", picUrl.Url); }
public Task <bool> Init(string key, string secret, bool useSandbox) { if (_finalLogin == null) { _client = new DropNetClient(key, secret) { UseSandbox = useSandbox } } ; else { _client = new DropNetClient(key, secret, _finalLogin.Token, _finalLogin.Secret) { UseSandbox = useSandbox }; return(Task.Factory.StartNew(() => true)); } var tcs = new TaskCompletionSource <bool>(); _client.GetTokenAsync(login => { SingInUrl = _client.BuildAuthorizeUrl(); tcs.SetResult(true); }, tcs.SetException); return(tcs.Task); }
public void Autorize(Action afterAction = null) { var redirectUri = "http://localhost:8080/"; Process.Start(_client.BuildAuthorizeUrl(OAuth2AuthorizationFlow.Code, redirectUri)); var http = new HttpListener { Prefixes = { redirectUri } }; http.Start(); http.BeginGetContext(result => { var context = http.EndGetContext(result); var response = Encoding.UTF8.GetBytes( "<script>window.onload=function(){open('http://dropbox.com', '_self');};</script>"); context.Response.ContentLength64 = response.Length; context.Response.OutputStream.Write(response, 0, response.Length); context.Response.OutputStream.Flush(); var ul = _client.GetAccessToken(context.Request.QueryString["code"], redirectUri); http.Stop(); http.Close(); _registyKey.SetValue(RegistryKey, ul.Token); _client.UserLogin = ul; _isAutorized = true; if (afterAction != null) afterAction(); }, null); }
/// <summary> /// Obtain the authorization URL to redirect the user to. /// </summary> /// <param name="callback">URL to send the user to after OAuth has been successful</param> /// <returns>Authorization URL</returns> public string BuildAuthorizationUrl(string callback) { if (_isAccessToken) throw new InvalidOperationException("User already authorized"); return _dropboxClient.BuildAuthorizeUrl(Token, callback); }
public string GetConnectUrl(DropNetClient client, string callbackurl) { _client = client; var url = _client.BuildAuthorizeUrl(callbackurl); return(url); }
static void Main(string[] args) { Console.WriteLine("You must first login in your dropbox account."); string currentDir = Directory.GetCurrentDirectory(); DirectoryInfo info = new DirectoryInfo(currentDir).Parent.Parent; FileInfo[] pictures = info.GetFiles("*.jpg"); List <int> indexesOfChosen = new List <int>(); PrintAndChoosePictures(pictures, indexesOfChosen); DropNetClient client = new DropNetClient("8lc93q5ybq85syv", "nt6wrs7m0maixnl"); var token = client.GetToken(); var url = client.BuildAuthorizeUrl(); Clipboard.SetText(url); Console.WriteLine("\n\nUrl copied to clipboard. Paste in browser and allow.\nPress any key to continue", url); Console.ReadKey(true); var accessToken = client.GetAccessToken(); client.UserLogin.Secret = accessToken.Secret; client.UserLogin.Token = accessToken.Token; client.UseSandbox = true; Console.Write("Enter album name: "); var albumName = Console.ReadLine(); var folder = client.CreateFolder(albumName); Console.WriteLine("\nUploading...\n"); foreach (var i in indexesOfChosen) { MemoryStream sr = new MemoryStream((int)pictures[i].Length); FileStream fs = File.Open(pictures[i].FullName, FileMode.Open); var bytes = new byte[fs.Length]; fs.Read(bytes, 0, Convert.ToInt32(fs.Length)); client.UploadFile(folder.Path, pictures[i].Name, bytes); fs.Close(); } var shareUrl = client.GetShare(folder.Path); Clipboard.SetText(shareUrl.Url); Console.WriteLine(shareUrl.Url); Console.WriteLine("Share Url is also in clipboard"); }
protected void btnStart_Click(object sender, EventArgs e) { Session["DropNetUserLogin"] = _client.GetToken(); var url = _client.BuildAuthorizeUrl(Request.Url.ToString() + "?dropboxcallback=1"); Response.Redirect(url); }
public async void AskUserForPermission(IExternalBrowserService externalBrowserService) { _client = new DropNetClient(AppKey, AppSecret); var token = await _client.GetRequestToken(); var url = _client.BuildAuthorizeUrl(token); externalBrowserService.OpenUrl(url); }
public Task <string> GetOAuthToken() { return(Task.Run(() => { _client.GetToken(); var tokenUrl = _client.BuildAuthorizeUrl("http://aloisdg.github.io/Nepholo/"); return tokenUrl; })); }
public async Task Given_UserToken_When_Build_Auth_Url_Then_The_Authentication_Url_Is_Returned() { var client = new DropNetClient(AppKey, AppSecret); var userToken = await client.GetRequestTokenAsync(); string url = client.BuildAuthorizeUrl(userToken, "http://cloudyboxapp.com"); Assert.IsNotEmpty(url); }
protected void dropbox(object sender, EventArgs e) { DropNetClient _client = new DropNetClient(_settings.dropbox_api_key(), _settings.dropbox_api_secret()); Session["request_token"] = _client.GetToken(); Session["dropbox_event_id"] = Page.RouteData.Values["id"] as string; var url = _client.BuildAuthorizeUrl(_settings.dropbox_return_url()); Response.Redirect(url); }
public ActionResult Connect() { if (CurrentUser.DropboxAccount != null) { return(RedirectToAction <UserController>(c => c.Index())); } UserLoginInfo = dropNetClient.GetToken(); var url = dropNetClient.BuildAuthorizeUrl(Request.Url + "CallBack"); return(Redirect(url)); }
protected void auth_dropbox(object sender, EventArgs e) { DropNetClient _client = new DropNetClient(_settings.dropbox_api_key(), _settings.dropbox_api_secret()); Session["request_token"] = _client.GetToken(); Session["dropbox_event_id"] = Session["event_id"].ToString(); var url = _client.BuildAuthorizeUrl(_settings.dropbox_return_url()); Response.Redirect(url); }
public string GetAuthorizationUrl() { DropNetClient _client = new DropNetClient(AppConstants.DropboxClientId, AppConstants.DropboxClientSecret); var token = _client.GetToken(); Storage.Dropbox.Token = token; var url = _client.BuildAuthorizeUrl(RedirectUrl + "?dropboxcallback=1"); return(url); }
/// <summary> /// Use a breakpoint to set-up a connection to your DropBox app and follow the described /// steps /// </summary> public void SetUp() { _dropBoxClient.GetToken(); // copy URL into the browser and log into dropbox var url = _dropBoxClient.BuildAuthorizeUrl(); // save token information into the config var token = _dropBoxClient.GetAccessToken(); _dropBoxClient.UserLogin = token; }
public async Task Get_Access_Token_Test() { var client = new DropNetClient(AppKey, AppSecret); var userToken = await client.GetRequestTokenAsync(); //Open the url in browser and login string url = client.BuildAuthorizeUrl(userToken, "http://cloudyboxapp.com"); var user = await client.GetAccessTokenAsync(); Assert.NotNull(user); }
private void AddAccountButton_Click(object sender, RoutedEventArgs e) { var serviceConfig = XDocument.Load(_dropboxfsAppConfig); if (serviceConfig.Root == null) { return; } var appKey = serviceConfig.Root.XPathSelectElement("//appSettings/add[@key='ApplicationKey']").Attribute("value").Value; var appSecret = serviceConfig.Root.XPathSelectElement("//appSettings/add[@key='ApplicationSecret']").Attribute("value").Value; if (string.IsNullOrWhiteSpace(appKey) || string.IsNullOrWhiteSpace(appSecret)) { return; } var dropNetclient = new DropNetClient(appKey, appSecret); dropNetclient.GetToken(); var url = dropNetclient.BuildAuthorizeUrl("http://127.0.0.1:64646/callback/"); var callbackResult = new DropboxCallbackListener(dropNetclient); ThreadPool.QueueUserWorkItem(DropboxCallbackListener.ProcessDropboxCallback, callbackResult); Process.Start(url); var count = 0; // we'll count how long the process can wait. 4 mins seems more than enough do { count++; } while (!WaitHandle.WaitAll(new WaitHandle[] { callbackResult.Done }, 5000) || count < 48); if (callbackResult.UserLogin == null) { throw new Exception("Timed out waiting for Dropbox oAuth callback. Try again"); } // if everything is alright - update the config with a new authorized account dropNetclient.UserLogin = callbackResult.UserLogin; var info = dropNetclient.AccountInfo(); var name = info.display_name ?? info.email; var accountsRoot = serviceConfig.Root.XPathSelectElement("//clientAccounts"); var account = new XElement("add"); account.SetAttributeValue("name", name); account.SetAttributeValue("key", callbackResult.UserLogin.Token); account.SetAttributeValue("secret", callbackResult.UserLogin.Secret); accountsRoot.Add(account); serviceConfig.Save(_dropboxfsAppConfig); UpdateAccountList(); }
public static void Main() { var client = new DropNetClient(apiKey, apiSecret); client.GetToken(); var url = client.BuildAuthorizeUrl(); Console.WriteLine("Open \"{0}\" in browser.", url); Console.WriteLine("Press [Enter] when you click on [Allow]"); OpenBrowser(url); Console.ReadLine(); client.GetAccessToken(); client.UseSandbox = true; var metaData = client.CreateFolder("HW-Pictures - " + date); string[] dir = Directory.GetFiles("../../images/", "*.jpg"); foreach (var file in dir) { Console.Write("Uploading"); while (true) { FileStream stream = File.Open(file, FileMode.Open); var bytes = new byte[stream.Length]; stream.Read(bytes, 0, (int)stream.Length); client.UploadFile("/" + metaData.Name, file.Substring(6), bytes); for (var i = 0; i < 10; i++) { Console.Write("."); Thread.Sleep(300); } stream.Close(); Console.WriteLine(); break; } } Console.WriteLine("Done!"); var pictureUrl = client.GetShare(metaData.Path); OpenBrowser(pictureUrl.Url); }
private void browser_Loaded(object sender, RoutedEventArgs e) { if (!Network.CheckNetwork()) { return; } _client.GetTokenAsync(x => { var url = _client.BuildAuthorizeUrl(x, CALL_BACK); url = "https://www.dropbox.com/logout?cont=" + HttpUtility.UrlEncode(url); Dispatcher.BeginInvoke(() => browser.Navigate(new Uri(url))); }, ex => ShowError()); }
private void Login() { try { if (_client == null) { _client = new DropNetClient(AppKey, AppSecret); _client.GetToken(); } var url = _client.BuildAuthorizeUrl(Server); _miniWebServer = new MiniWebServer(SendResponse, Server); _miniWebServer.Run(); PhotoUtils.Run(url); } catch (Exception) { Log.Error("Unable to login"); } }
public DropStorage(Action <string> webViewCallback) { _webViewCallback = webViewCallback; _client = new DropNetClient(DROPBOX_APP_KEY, DROPBOX_APP_SECRET); //Get Request Token _client.GetToken(); var authUri = _client.BuildAuthorizeUrl(); //Process.Start(authUri); _webViewCallback(authUri); //don't need it, web view callback is blocking //var dlg = new AuthDlg(StorageType.Dropbox); //dlg.ShowDialog(); _accessToken = _client.GetAccessToken(); //Store this token for "remember me" function }
void DoIt() { try { var tokenUrl = client.BuildAuthorizeUrl(); //Use your own callback Url here if (CloudManagerUI.AuthWindowDB.IsActiveProperty != null) { string startUrl = tokenUrl.ToString(); string endUrl = "authorize_submit"; this.authForm = new AuthWindowDB( startUrl, endUrl, OnAuthCompleted); this.authForm.Closed += authForm_Closed; this.authForm.ShowDialog(); } } catch (Exception e) { string temp = e.Message; } }
static public void syncAcc(bool resync) { //Testing Connection try { Ping pSender = new Ping(); PingReply pResult = pSender.Send("8.8.8.8"); if (pResult.Status == IPStatus.Success) { Console.WriteLine("Internet available"); } else { Exception exc = new Exception("no internetconnection"); throw exc; } } catch (Exception) { MessageBox.Show("Please make sure your connection to the internet is available"); return; } DropNetClient dbClient = new DropNetClient(Program.Config.AppKey, Program.Config.AppSecret); #if DEBUG dbClient.UseSandbox = true; #endif if (String.IsNullOrEmpty(Properties.Settings.Default.DropBoxUserToken) || resync) { try { dbClient.GetToken(); } catch (Exception) { throw; } var url = dbClient.BuildAuthorizeUrl(); Browser_frm browser = new Browser_frm(url); browser.ShowDialog(); try { var accessToken = dbClient.GetAccessToken(); MessageBox.Show(accessToken.Token); Properties.Settings.Default.DropBoxUserSecret = accessToken.Secret; Properties.Settings.Default.DropBoxUserToken = accessToken.Token; Properties.Settings.Default.Save(); MessageBox.Show("Login Saved"); } catch (Exception) { throw; } } else { MessageBox.Show("already synchronized"); } }