Skip to content

Commit 3028825

Browse files
Merge pull request KelvinTegelaar#1541 from kris6673/app-consent
Fix: Fix table filter and enhance app consent request handling
2 parents 17c489e + b737c18 commit 3028825

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tenant/Administration/Invoke-ListAppConsentRequests.ps1

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,33 @@ function Invoke-ListAppConsentRequests {
1515

1616
# Interact with query parameters or the body of the request.
1717
$TenantFilter = $Request.Query.tenantFilter
18+
$RequestStatus = $Request.Query.RequestStatus
19+
$Filter = $Request.Query.Filter
1820

1921
try {
2022
if ($TenantFilter -eq 'AllTenants') {
2123
throw 'AllTenants is not yet supported'
2224
}
2325

24-
$appConsentRequests = New-GraphGetRequest -Uri 'https://graph.microsoft.com/beta/identityGovernance/appConsent/appConsentRequests' -tenantid $TenantFilter # Need the beta endpoint to get consentType
26+
# Apply server-side filtering if requested
27+
$Uri = 'https://graph.microsoft.com/beta/identityGovernance/appConsent/appConsentRequests' # Need the beta endpoint to get consentType
28+
if ($Filter -eq $true -and $RequestStatus) {
29+
switch ($RequestStatus) {
30+
'InProgress' {
31+
$FilterQuery = "userConsentRequests/any (u:u/status eq '$RequestStatus')"
32+
$Uri = "$Uri`?`$filter=$([System.Web.HttpUtility]::UrlEncode($FilterQuery))"
33+
Write-Host "Applying server-side filter for RequestStatus: $RequestStatus"
34+
$ServerSideFilteringApplied = $true
35+
}
36+
default {
37+
# All the other values are not supported yet even if the Graph API docs say they are. -Bobby
38+
$ServerSideFilteringApplied = $false
39+
}
40+
}
41+
}
42+
43+
$appConsentRequests = New-GraphGetRequest -Uri $Uri -tenantid $TenantFilter
44+
2545
$Results = foreach ($app in $appConsentRequests) {
2646
$userConsentRequests = New-GraphGetRequest -Uri "https://graph.microsoft.com/v1.0/identityGovernance/appConsent/appConsentRequests/$($app.id)/userConsentRequests" -tenantid $TenantFilter
2747
$userConsentRequests | ForEach-Object {
@@ -48,12 +68,19 @@ function Invoke-ListAppConsentRequests {
4868
}
4969
}
5070
}
71+
72+
# Apply filtering if requested. Has to be done before and after the foreach loop, as the serverside filter is only supported for InProgress.
73+
if ($Filter -eq $true -and $ServerSideFilteringApplied -eq $false) {
74+
if ($RequestStatus) {
75+
Write-Host "Filtering by RequestStatus: $RequestStatus"
76+
$Results = $Results | Where-Object { $_.requestStatus -eq $RequestStatus }
77+
}
78+
}
5179
$StatusCode = [HttpStatusCode]::OK
5280
} catch {
5381
$ErrorMessage = Get-CippException -Exception $_
5482
$StatusCode = [HttpStatusCode]::InternalServerError
55-
Write-LogMessage -Headers $Headers -API $APIName -message 'app consent request list failed' -Sev 'Error' -tenant $TenantFilter -LogData $ErrorMessage
56-
$Results = @{ appDisplayName = "Error: $($ErrorMessage.NormalizedError)" }
83+
$Results = "Error: $($ErrorMessage.NormalizedError)"
5784
}
5885

5986
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{

0 commit comments

Comments
 (0)