public void GenerateAuthInfos_ValidCredentials_Succeeds(string email, string password, string expectedResult) { var authInfos = MegaApiClient.GenerateAuthInfos(email, password); var result = JsonConvert.SerializeObject(authInfos, Formatting.None).Replace('\"', '\''); Assert.Equal(expectedResult, result); }
async void Checkup() { var wait = DevExpress.XtraSplashScreen.SplashScreenManager.ShowOverlayForm(this.simpleButton1); progressBarControl1.Properties.Minimum = 0; progressBarControl1.Properties.Maximum = main_lista.Count; progressBarControl1.Properties.Step = 1; progressBarControl1.Properties.PercentView = true; try { foreach (var klijent in main_lista) { MegaApiClient mega = new MegaApiClient(); var auth = mega.GenerateAuthInfos(klijent.username, klijent.pass); mega.Login(auth); var nodes = await mega.GetNodesAsync(); klijent.zadnji_upload = nodes.Where(n => n.Type == NodeType.File).Max(xx => xx.CreationDate); gridControl1.Refresh(); gridView1.RefreshData(); progressBarControl1.PerformStep(); progressBarControl1.Update(); } } catch (Exception ex) { DevExpress.XtraSplashScreen.SplashScreenManager.CloseOverlayForm(wait); XtraMessageBox.Show(ex.Message); } DevExpress.XtraSplashScreen.SplashScreenManager.CloseOverlayForm(wait); progressBarControl1.EditValue = 0; }
private void buttonAcc_Click(object sender, EventArgs e) { try { if (_client.IsLoggedIn) { _client.Logout(); } _authInfos = _client.GenerateAuthInfos(textBoxLogin.Text, textBoxPassw.Text); _token = _client.Login(_authInfos); if (!_client.IsLoggedIn) { throw new IOException("Client did not log in"); } DialogResult = DialogResult.OK; Close(); } catch (Exception ex) { MessageBox.Show("Failed to log in with the specified login and password. Please make sure that they are correct and you are connected to the internet, then try again.\n\nError message: " + ex.Message, "Log in to mega.nz", MessageBoxButtons.OK, MessageBoxIcon.Error); DialogResult = DialogResult.None; } }
public async Task <LoginReturnMessage> LoginWithCredentials(string username, SecureString password, string?mfa) { MegaApiClient.AuthInfos authInfos; try { MegaApiClient.Logout(); } catch (NotSupportedException) { // Not logged in, so ignore } try { authInfos = MegaApiClient.GenerateAuthInfos(username, password.ToNormalString(), mfa); } catch (ApiException e) { return(e.ApiResultCode switch { ApiResultCode.BadArguments => new LoginReturnMessage($"Email or password was wrong! {e.Message}", LoginReturnCode.BadCredentials), ApiResultCode.InternalError => new LoginReturnMessage( $"Internal error occured! Please report this to the Wabbajack Team! {e.Message}", LoginReturnCode.InternalError), _ => new LoginReturnMessage($"Error generating authentication information! {e.Message}", LoginReturnCode.InternalError) });
public void Oauth(CloudType type) { CheckThread(true); Type type_oauthUI; switch (type) { case CloudType.Dropbox: DropboxOauthv2 oauth_dropbox = new DropboxOauthv2(); oauth_dropbox.TokenCallBack += Oauth_dropbox_TokenCallBack; type_oauthUI = LoadDllUI.GetTypeInterface(typeof(UIinterfaceDB)); AppSetting.UIOauth = (OauthUI)Activator.CreateInstance(type_oauthUI); oauth_dropbox.GetCode(AppSetting.UIOauth, AppSetting.UIMain); break; case CloudType.GoogleDrive: GoogleAPIOauth2 oauth_gd = new GoogleAPIOauth2(); oauth_gd.TokenCallBack += Oauth_gd_TokenCallBack; type_oauthUI = LoadDllUI.GetTypeInterface(typeof(UIinterfaceGD)); AppSetting.UIOauth = (OauthUI)Activator.CreateInstance(type_oauthUI); oauth_gd.GetCode(AppSetting.UIOauth, AppSetting.UIMain); break; case CloudType.Mega: type_oauthUI = LoadDllUI.GetTypeInterface(typeof(UIinterfaceMegaNz)); UIinterfaceMegaNz mega = (UIinterfaceMegaNz)Activator.CreateInstance(type_oauthUI); bool error = false; reoauthMega: if (!error) { mega.ShowDialog_(); } else { mega.ShowError("Wrong email or password."); } if (mega.Success) { MegaApiClient.AuthInfos oauthinfo = MegaApiClient.GenerateAuthInfos(mega.Email, mega.Pass); MegaApiClient client = new MegaApiClient(); try { client.Login(oauthinfo); } catch (Exception) { error = true; goto reoauthMega; } SaveToken(mega.Email, JsonConvert.SerializeObject(oauthinfo), CloudType.Mega); } break; default: throw new Exception("Not support"); } }
public void GenerateAuthInfos_InvalidCredentials_Throws(string email, string password) { Assert.That(() => MegaApiClient.GenerateAuthInfos(email, password), Throws.TypeOf <ArgumentNullException>() .With.Property <ArgumentNullException>(x => x.ParamName).EqualTo("email") .Or.With.Property <ArgumentNullException>(x => x.ParamName).EqualTo("password")); }
public void Login_DeserializedAuthInfos_Succeeds(string email, string password) { var authInfos = MegaApiClient.GenerateAuthInfos(email, password); var serializedAuthInfos = JsonConvert.SerializeObject(authInfos, Formatting.None).Replace('\"', '\''); var deserializedAuthInfos = JsonConvert.DeserializeObject <MegaApiClient.AuthInfos>(serializedAuthInfos); this.context.Client.Login(deserializedAuthInfos); Assert.True(this.context.Client.IsLoggedIn); }
public void Login_DeserializedAuthInfos_Succeeds(string email, string password) { var authInfos = MegaApiClient.GenerateAuthInfos(email, password); var serializedAuthInfos = JsonConvert.SerializeObject(authInfos, Formatting.None).Replace('\"', '\''); var deserializedAuthInfos = JsonConvert.DeserializeObject <MegaApiClient.AuthInfos>(serializedAuthInfos); Assert.That( () => this.Client.Login(deserializedAuthInfos), Throws.Nothing); }
public FormDownload(Form1.Klijenti _klijent) { InitializeComponent(); dateEdit1.EditValue = DateTime.Now; klijent = _klijent; listagrid = new List <BazeGrid>(); mega = new MegaApiClient(); var auth = mega.GenerateAuthInfos(klijent.username, klijent.pass); mega.Login(auth); }
private void btnMegaLogin_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtMegaEmail.Text) || string.IsNullOrEmpty(txtMegaPassword.Text)) { return; } Config.MegaAuthInfos = MegaApiClient.GenerateAuthInfos(txtMegaEmail.Text, txtMegaPassword.Text); MegaConfigureTab(true); }
private void barButtonItem2_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { Klijenti red = (Klijenti)gridView1.GetRow(gridView1.FocusedRowHandle); var klijent = main_lista.FirstOrDefault(qq => qq.username == red.username); MegaApiClient mega = new MegaApiClient(); var auth = mega.GenerateAuthInfos(klijent.username, klijent.pass); mega.Login(auth); var nodes = mega.GetNodes(); klijent.zadnji_upload = nodes.Where(n => n.Type == NodeType.File).Max(xx => xx.CreationDate); gridControl1.Refresh(); gridView1.RefreshData(); }
public MegaUpdater(Uri serverUri, NetworkCredential credentials) { if (serverUri.Host.ToLower() != "mega.nz") { throw new NotSupportedException("The link doesn't point to mega.nz - " + serverUri); } var client = new MegaApiClient(); _client = client; if (credentials != null) { _authInfos = _client.GenerateAuthInfos(credentials.UserName, credentials.Password); } CurrentFolderLink = serverUri; }
public LoginReturnMessage LoginWithCredentials(string username, SecureString password) { MegaApiClient.AuthInfos authInfos; try { authInfos = MegaApiClient.GenerateAuthInfos(username, password.ToNormalString()); } catch (ApiException e) { return(e.ApiResultCode switch { ApiResultCode.BadArguments => new LoginReturnMessage($"Email or password was wrong! {e.Message}", true), ApiResultCode.InternalError => new LoginReturnMessage( $"Internal error occured! Please report this to the Wabbajack Team! {e.Message}", true), _ => new LoginReturnMessage($"Error generating authentication information! {e.Message}", true) });
public MegaUpdater(Uri serverUri, int discoveryPriority, int downloadPriority = 10, NetworkCredential credentials = null) : base(serverUri.OriginalString, discoveryPriority, downloadPriority) { if (serverUri == null) { throw new ArgumentNullException(nameof(serverUri)); } if (serverUri.Host.ToLower() != "mega.nz") { throw new NotSupportedException("The link doesn't point to mega.nz - " + serverUri); } _client = new MegaApiClient(); _client.ApiRequestFailed += (sender, args) => Console.WriteLine($@"MEGA API ERROR: {args.ApiResult} {args.Exception}"); _currentFolderLink = serverUri; try { if (credentials != null) { _authInfos = _client.GenerateAuthInfos(credentials.UserName, credentials.Password); } else if (!string.IsNullOrWhiteSpace(Settings.Default.mega_authInfos)) { _authInfos = JsonConvert.DeserializeObject <MegaApiClient.AuthInfos>(Settings.Default.mega_authInfos); } } catch (Exception ex) { Console.WriteLine("Failed to create MegaApiClient.AuthInfos - " + ex.ToStringDemystified()); } try { if (!string.IsNullOrWhiteSpace(Settings.Default.mega_sessionToken)) { _loginToken = JsonConvert.DeserializeObject <MegaApiClient.LogonSessionToken>(Settings.Default.mega_sessionToken); } } catch (Exception ex) { Console.WriteLine("Failed to read stored MegaApiClient.LogonSessionToken - " + ex.ToStringDemystified()); } }
private void Button2_Click(object sender, EventArgs e) { void Fail(string s) => MessageBox.Show(this, s, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); if (!_chrs.ContainsKey(comboBox1.SelectedIndex)) { Fail("You must select a drive letter for the target drive."); } else { MegaApiClient.AuthInfos auth; if (_settings.Hash?.Any() ?? false) { auth = new MegaApiClient.AuthInfos(_settings.Email, _settings.Hash, _settings.AES ?? new byte[0]); } else { auth = MegaApiClient.GenerateAuthInfos(textBox1.Text, maskedTextBox1.Text); } try { _settings.LastToken = _mega.Login(auth); _settings.Hash = auth.Hash; _settings.Email = auth.Email; _settings.AES = auth.PasswordAesKey; _settings.Save = checkBox1.Checked; _settings.Drive = _chrs[comboBox1.SelectedIndex]; _settings.DeleteCache = checkBox2.Checked; _settings.CacheSz = (int)numericUpDown1.Value; Close(); } catch { _settings.LastToken = null; Fail("The combination of Email-address and password is invalid."); } } }
/// <summary> /// Generates a JSON file with login encrypted data to use with Mega Api /// </summary> /// <returns>true if everything went ok</returns> public static bool GetAuthInfo() { try { MegaApiClient client = new MegaApiClient(); AuthInfos AU = MegaApiClient.GenerateAuthInfos("*****@*****.**", "password"); //Your email and pass used to create the mega account MegaApiClient.AuthInfos AF = AU; // = new MegaApiClient.AuthInfos() MessageBox.Show(AF.PasswordAesKey.ToString()); string json = JsonConvert.SerializeObject(AF); JObject Auth = (JObject)JToken.FromObject(AF); // write JSON directly to a file using (StreamWriter file = File.CreateText("C:/Auth.json")) //location where the json file is going to be saved using (JsonTextWriter writer = new JsonTextWriter(file)) { Auth.WriteTo(writer); } return(true); } catch { return(false); } }
public static async Task <MegaApiClient> LoginAsync(string account, string code, string settingsPassPhrase) { if (string.IsNullOrEmpty(account)) { throw new ArgumentNullException(nameof(account)); } var client = new MegaApiClient(); var refreshToken = LoadRefreshToken(account, settingsPassPhrase); if (refreshToken != null) { await client.LoginAsync(refreshToken); } else { if (string.IsNullOrEmpty(code)) { code = GetAuthCode(account); } var parts = code?.Split(new[] { ',' }, 2) ?? Array.Empty <string>(); if (parts.Length != 2) { throw new AuthenticationException(string.Format(CultureInfo.CurrentCulture, Properties.Resources.ProvideAuthenticationData, account)); } refreshToken = MegaApiClient.GenerateAuthInfos(parts[0], parts[1]); client.Login(refreshToken); } SaveRefreshToken(account, refreshToken, settingsPassPhrase); return(client); }
public void GenerateAuthInfos_InvalidCredentials_Throws(string email, string password, string expectedMessage) { Assert.Throws <ArgumentNullException>(expectedMessage, () => MegaApiClient.GenerateAuthInfos(email, password)); }
public string GenerateAuthInfos_ValidCredentials_Succeeds(string email, string password) { var authInfos = MegaApiClient.GenerateAuthInfos(email, password); return(JsonConvert.SerializeObject(authInfos, Formatting.None).Replace('\"', '\'')); }