Skip to content

Commit 8c338eb

Browse files
committed
feat: Better alert message for NewAppApproval alert
1 parent f3d5cd0 commit 8c338eb

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

Modules/CIPPCore/Public/Alerts/Get-CIPPAlertNewAppApproval.ps1

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,25 @@ function Get-CIPPAlertNewAppApproval {
1313
$Headers
1414
)
1515
try {
16-
$Approvals = New-GraphGetRequest -Uri "https://graph.microsoft.com/v1.0/identityGovernance/appConsent/appConsentRequests?`$filter=userConsentRequests/any (u:u/status eq 'InProgress')" -tenantid $TenantFilter
16+
$Approvals = New-GraphGetRequest -Uri "https://graph.microsoft.com/beta/identityGovernance/appConsent/appConsentRequests?`$filter=userConsentRequests/any (u:u/status eq 'InProgress')" -tenantid $TenantFilter
1717
if ($Approvals.count -gt 0) {
18-
$AlertData = "There are $($Approvals.count) App Approval(s) pending."
18+
$AlertData = [System.Collections.Generic.List[string]]::new()
19+
foreach ($App in $Approvals) {
20+
$userConsentRequests = New-GraphGetRequest -Uri "https://graph.microsoft.com/v1.0/identityGovernance/appConsent/appConsentRequests/$($App.id)/userConsentRequests" -tenantid $TenantFilter
21+
$userConsentRequests | ForEach-Object {
22+
$consentUrl = if ($App.consentType -eq 'Static') {
23+
# if something is going wrong here you've probably stumbled on a fourth variation - rvdwegen
24+
"https://login.microsoftonline.com/$($TenantFilter)/adminConsent?client_id=$($App.appId)&bf_id=$($App.id)&redirect_uri=https://entra.microsoft.com/TokenAuthorize"
25+
} elseif ($App.pendingScopes.displayName) {
26+
"https://login.microsoftonline.com/$($TenantFilter)/v2.0/adminConsent?client_id=$($App.appId)&scope=$($App.pendingScopes.displayName -Join(' '))&bf_id=$($App.id)&redirect_uri=https://entra.microsoft.com/TokenAuthorize"
27+
} else {
28+
"https://login.microsoftonline.com/$($TenantFilter)/adminConsent?client_id=$($App.appId)&bf_id=$($App.id)&redirect_uri=https://entra.microsoft.com/TokenAuthorize"
29+
}
30+
31+
$Message = "App name: $($App.appDisplayName) - Request user: $($_.createdBy.user.userPrincipalName) - Reason: $($_.reason)`nApp Id: $($App.appId) - Scopes: $($App.pendingScopes.displayName)`nConsent URL: $consentUrl"
32+
$AlertData.Add($Message)
33+
}
34+
}
1935
Write-AlertTrace -cmdletName $MyInvocation.MyCommand -tenantFilter $TenantFilter -data $AlertData
2036
}
2137
} catch {

0 commit comments

Comments
 (0)