Skip to content

Commit 69b56df

Browse files
author
bjansen
committed
Admin library: ACS principals created as of December 2024 are regular Entra apps, ensure the principal validity is loaded correctly
1 parent 331a728 commit 69b56df

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

src/sdk/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
4242
- Page API: maintain full width header section in combination with vertical section #1615 #1629 [nicolaor - Rene Nicolao]
4343
- Additional header check for BatchClient #1635 [koenzomers - Koen Zomers]
4444
- Prevent blank lines when html tags have attributes #1636 [robi26 - Stephan Steiger]
45+
- Admin library: ACS principals created as of December 2024 are regular Entra apps, ensure the principal validity is loaded correctly [jansenbe - Bert Jansen]
46+
4547

4648
## [1.14]
4749

src/sdk/PnP.Core.Admin/Model/SharePoint/Core/Internal/LegacyPrincipalManagement.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,14 @@ internal async static Task<List<ACSPrincipal>> GetACSPrincipalsAsync(PnPContext
219219
}
220220
}
221221

222+
if (tempACSPrincipal.ValidUntil == DateTime.MinValue)
223+
{
224+
// The principal was not retrieved as part of the legacy service principals, this can happen because
225+
// since end of 2024 we're creating ACS principals as regular Entra app which do not have the
226+
// legacyServicePrincipal type set to Legacy
227+
await UpdateACSPrincipalDataWithEntraAppPropertiesAsync(context, tempACSPrincipal).ConfigureAwait(false);
228+
}
229+
222230
if (acsPrincipal.TryGetProperty("appDomains", out JsonElement appDomains) && appDomains.ValueKind == JsonValueKind.Array)
223231
{
224232
List<string> appDomainList = new();
@@ -326,6 +334,31 @@ internal async static Task<List<ACSPrincipal>> GetACSPrincipalsAsync(PnPContext
326334
return acsPrincipals;
327335
}
328336

337+
private static async Task UpdateACSPrincipalDataWithEntraAppPropertiesAsync(PnPContext context, ACSPrincipal tempACSPrincipal)
338+
{
339+
var response = await (context.Web as Web).RawRequestAsync(new ApiCall(string.Format("applications?$filter=appid eq '{0}'&$select=id,appId,passwordCredentials,displayName", tempACSPrincipal.AppId), ApiType.Graph), HttpMethod.Get).ConfigureAwait(false);
340+
341+
var jsonResponse2 = JsonSerializer.Deserialize<JsonElement>(response.Json);
342+
if (jsonResponse2.TryGetProperty("value", out JsonElement appArray) && appArray.ValueKind == JsonValueKind.Array)
343+
{
344+
foreach (var acsApp in appArray.EnumerateArray())
345+
{
346+
if (acsApp.TryGetProperty("passwordCredentials", out JsonElement keyCredentials) && keyCredentials.ValueKind == JsonValueKind.Array)
347+
{
348+
// Only include service principals which are still valid
349+
foreach (var keyCredential in keyCredentials.EnumerateArray())
350+
{
351+
if (keyCredential.TryGetProperty("endDateTime", out JsonElement endDateTime))
352+
{
353+
tempACSPrincipal.ValidUntil = endDateTime.GetDateTime();
354+
return;
355+
}
356+
}
357+
}
358+
}
359+
}
360+
}
361+
329362
internal static async Task<List<ILegacyServicePrincipal>> GetValidLegacyServicePrincipalAppIdsAsync(PnPContext context, bool includeExpiredPrincipals, VanityUrlOptions vanityUrlOptions)
330363
{
331364
List<ILegacyServicePrincipal> servicePrincipals = new();

0 commit comments

Comments
 (0)