Skip to content

Commit

Permalink
Add helper methods to get/delete a tenant in the configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Yvand committed Jun 20, 2024
1 parent 34fcf01 commit 110194c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Unreleased

* Fix an NullReferenceException in a very rare scenario where ClaimsPrincipal.Identity is null
* Add helper methods to get/delete a tenant in the configuration

## EntraCP v25.0.20240503.33 enhancements & bug-fixes - Published in May 3, 2024

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ public bool UpdateTenantCredentials(string tenantName, string newClientSecret, s
throw new ArgumentNullException(nameof(newClientSecret));
}

EntraIDTenant tenant = this.EntraIDTenants.FirstOrDefault(x => x.Name.Equals(tenantName, StringComparison.InvariantCultureIgnoreCase));
EntraIDTenant tenant = GetTenantConfiguration(tenantName);
if (tenant == null) { return false; }
string clientId = String.IsNullOrWhiteSpace(newClientId) ? tenant.ClientId : newClientId;
return tenant.SetCredentials(clientId, newClientSecret);
Expand All @@ -426,13 +426,46 @@ public bool UpdateTenantCredentials(string tenantName, string newClientCertifica
throw new ArgumentNullException(nameof(tenantName));
}

EntraIDTenant tenant = this.EntraIDTenants.FirstOrDefault(x => x.Name.Equals(tenantName, StringComparison.InvariantCultureIgnoreCase));
EntraIDTenant tenant = GetTenantConfiguration(tenantName);
if (tenant == null) { return false; }

string clientId = String.IsNullOrWhiteSpace(newClientId) ? tenant.ClientId : newClientId;
return tenant.SetCredentials(clientId, newClientCertificatePfxFilePath, newClientCertificatePfxPassword);
}

/// <summary>
/// Gets the tenant configuration
/// </summary>
/// <param name="tenantName">Name of the tenant</param>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
public EntraIDTenant GetTenantConfiguration(string tenantName)
{
if (String.IsNullOrWhiteSpace(tenantName))
{
throw new ArgumentNullException(nameof(tenantName));
}
return this.EntraIDTenants.FirstOrDefault(x => x.Name.Equals(tenantName, StringComparison.OrdinalIgnoreCase));
}

/// <summary>
/// Deletes the tenant configuration
/// </summary>
/// <param name="tenantName">Name of the tenant</param>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
public bool DeleteTenantConfiguration(string tenantName)
{
if (String.IsNullOrWhiteSpace(tenantName))
{
throw new ArgumentNullException(nameof(tenantName));
}

EntraIDTenant tenant = GetTenantConfiguration(tenantName);
if (tenant == null) { return false; }
return this.EntraIDTenants.Remove(tenant);
}

/// <summary>
/// If it is valid, commits the current settings to the SharePoint settings database
/// </summary>
Expand Down

0 comments on commit 110194c

Please sign in to comment.