private async void uxComboBoxAccounts_SelectedIndexChanged(object sender, EventArgs e) { if (uxComboBoxAccounts.SelectedItem is string) { MessageBox.Show(AddDomainHintInstructions, Utils.AppName, MessageBoxButtons.OK, MessageBoxIcon.Information); uxComboBoxAccounts.SelectedItem = null; return; } _currentAccountItem = (AccountItem)uxComboBoxAccounts.SelectedItem; if (null == _currentAccountItem) { return; } using (var op = NewUxOperationWithProgress(uxComboBoxAccounts)) { var vaui = new VaultAccessUserInteractive(_currentAccountItem.DomainHint); _currentAuthResult = vaui.AcquireToken(_currentAccountItem.AuthContext, ManagmentEndpoint); _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(_currentAuthResult.AccessTokenType, _currentAuthResult.AccessToken); var hrm = await _httpClient.GetAsync($"{ManagmentEndpoint}subscriptions?{ApiVersion}", op.CancellationToken); var json = await hrm.Content.ReadAsStringAsync(); var subs = JsonConvert.DeserializeObject <SubscriptionsResponse>(json); uxListViewSubscriptions.Items.Clear(); uxListViewVaults.Items.Clear(); uxPropertyGridVault.SelectedObject = null; foreach (var s in subs.Subscriptions) { uxListViewSubscriptions.Items.Add(new ListViewItemSubscription(s)); } } }
private async void uxComboBoxAccounts_SelectedIndexChanged(object sender, EventArgs e) { switch (uxComboBoxAccounts.SelectedItem) { case null: return; case AddAccountText: AddNewAccount(); break; case AddDomainHintText: // Display instructions on how to add domain hint MessageBox.Show(AddDomainHintInstructions, Utils.AppName, MessageBoxButtons.OK, MessageBoxIcon.Information); uxComboBoxAccounts.SelectedItem = null; return; case AccountItem account: // Authenticate into selected account _currentAccountItem = account; GetAuthenticationToken(); _currentAccountItem.UserAlias = _currentAuthResult.UserInfo.DisplayableId.Split('@')[0]; break; default: return; } using (var op = NewUxOperationWithProgress(uxComboBoxAccounts)) { _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(_currentAuthResult.AccessTokenType, _currentAuthResult.AccessToken); var hrm = await _httpClient.GetAsync($"{ManagmentEndpoint}subscriptions?{ApiVersion}", op.CancellationToken); var json = await hrm.Content.ReadAsStringAsync(); var subs = JsonConvert.DeserializeObject <SubscriptionsResponse>(json); uxListViewSubscriptions.Items.Clear(); uxListViewVaults.Items.Clear(); uxPropertyGridVault.SelectedObject = null; foreach (var s in subs.Subscriptions) { uxListViewSubscriptions.Items.Add(new ListViewItemSubscription(s)); } } }
private void AddNewAccount() { // Create temp account item for new account _currentAccountItem = new AccountItem(Guid.NewGuid().ToString()); GetAuthenticationToken(); // Get new user account and add it to default settings string userAccountName = _currentAuthResult.UserInfo.DisplayableId; string[] userLogin = userAccountName.Split('@'); _currentAccountItem.UserAlias = userLogin[0]; _currentAccountItem.DomainHint = userLogin[1]; Settings.Default.AddUserAccountName(userAccountName); // Rename cache to be associated with user login ((FileTokenCache)_currentAccountItem.AuthContext.TokenCache).Rename(userAccountName); uxComboBoxAccounts.Items.Insert(0, userAccountName); uxComboBoxAccounts.SelectedIndex = 0; }