public TenantCredential(AadEnvironment environment, string tenant, string clientId, ApplicationType applicationType, string alias) { if (environment == null) { throw new ArgumentException(StringResources.EnvironmentCannotBeNull); } if (String.IsNullOrEmpty(tenant)) { throw new ArgumentException(StringResources.TenantCannotBeNullOrWhiteSpace); } if (String.IsNullOrWhiteSpace(clientId)) { throw new ArgumentException(StringResources.ClientIdCannotBeNullOrWhiteSpace); } Guid ignored; if (!Guid.TryParse(clientId, out ignored)) { throw new ArgumentException(StringResources.ClientIdMustBeAGuid); } this.Environment = environment; this.Tenant = tenant; this.ClientId = clientId; this.ApplicationType = applicationType; this.Alias = alias; }
public void Store(AadEnvironment environment) { string environmentPath = GetEnvironmentPath(environment); using (RegistryKey registryKey = Registry.CurrentUser.CreateSubKey(environmentPath)) { if (registryKey == null) { return; } registryKey.SetValue(LoginEndpointKey, environment.LoginEndpoint); registryKey.SetValue(GraphApiEndpointKey, environment.GraphApiEndpoint); } }
private void PopulateTenantCredentials(AadEnvironment environment, string lastSelectedTenantCredential = null) { if (environment == null) { return; } this.TenantCredentialComboBox.Items.Clear(); foreach (TenantCredential tenantCredential in this.Store.GetTenantCredentials(environment)) { this.TenantCredentialComboBox.Items.Add(tenantCredential); if (tenantCredential.ToString().Equals(lastSelectedTenantCredential, StringComparison.OrdinalIgnoreCase)) { this.TenantCredentialComboBox.SelectedItem = tenantCredential; } } this.TenantCredentialComboBox.Items.Add(StringResources.ManageItem); this.getAppTokenButton.Enabled = this.TenantCredentialComboBox.SelectedItem != null; }
private void environmentComboBox_SelectedIndexChanged(object sender, EventArgs e) { if (this.EnvironmentComboBox.SelectedItem == null) { return; } AadEnvironment environment = this.EnvironmentComboBox.SelectedItem as AadEnvironment; this.PopulateTenantCredentials(environment); this.urlBuilder.Environment = environment; this.apiVersionComboBox.Items.Clear(); if (environment != null) { foreach (string apiVersion in environment.ApiVersions) { this.apiVersionComboBox.Items.Add(apiVersion); } } }
public void Delete(AadEnvironment environment) { }
private static string GetTenantPath(AadEnvironment environment, string tenant) { string environmentPath = GetEnvironmentPath(environment); return(environmentPath + '\\' + tenant); }
private static string GetEnvironmentPath(AadEnvironment environment) { return(EnvironmentsRoot + '\\' + environment.RegistryName); }
public TenantCredentialSet GetTenantCredentials(AadEnvironment environment) { TenantCredentialSet tenantCredentials = new TenantCredentialSet(); string environmentPath = GetEnvironmentPath(environment); using (RegistryKey environmentKey = Registry.CurrentUser.OpenSubKey(environmentPath)) { if (environmentKey == null) { return(tenantCredentials); } foreach (string tenant in environmentKey.GetSubKeyNames()) { using (RegistryKey tenantKey = environmentKey.OpenSubKey(tenant)) { if (tenantKey == null) { continue; } foreach (string clientId in tenantKey.GetSubKeyNames()) { using (RegistryKey clientIdKey = tenantKey.OpenSubKey(clientId)) { if (String.IsNullOrWhiteSpace(clientId)) { continue; } if (clientIdKey == null) { continue; } string applicationTypeString = clientIdKey.GetValue(ApplicationTypeKey) as string; ApplicationType applicationType; if (!Enum.TryParse(applicationTypeString, true, out applicationType)) { continue; } string alias = clientIdKey.GetValue(AliasKey) as string; TenantCredential credential; try { credential = new TenantCredential(environment, tenant, clientId, applicationType, alias); } catch (Exception) { // Bad key, can't decrypt :-( continue; } switch (applicationType) { case ApplicationType.Native: string replyUrl = clientIdKey.GetValue(ReplyUrlKey) as string; if (string.IsNullOrWhiteSpace(replyUrl)) { continue; } credential.ReplyUrl = new Uri(replyUrl); break; case ApplicationType.Web: byte[] encryptedKey = clientIdKey.GetValue(EncryptedKeyKey) as byte[]; if (encryptedKey == null || encryptedKey.Length < 16) { continue; } credential.EncryptedKey = encryptedKey; break; default: // unknown application type :-( continue; } tenantCredentials.Add(credential); } } } } } return(tenantCredentials); }