Skip to content

Commit cde0cd3

Browse files
committed
add mfa service policy check
1 parent 6b6a3c0 commit cde0cd3

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

Modules/CIPPCore/Public/Test-CIPPAccessPermissions.ps1

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ function Test-CIPPAccessPermissions {
138138
$CPVRefreshList = [System.Collections.Generic.List[object]]::new()
139139
$CPVSuccess = $true
140140
foreach ($Tenant in $TenantList) {
141-
$LastRefresh = ($CpvRefresh | Where-Object { $_.RowKey -EQ $Tenant.customerId }).Timestamp.DateTime
141+
$LastRefresh = ($CpvRefresh | Where-Object { $_.RowKey -eq $Tenant.customerId }).Timestamp.DateTime
142142
if ($LastRefresh -lt $LastUpdate) {
143143
$CPVSuccess = $false
144144
$CPVRefreshList.Add([PSCustomObject]@{
@@ -157,6 +157,19 @@ function Test-CIPPAccessPermissions {
157157
$ErrorMessage = Get-CippException -Exception $_
158158
Write-LogMessage -Headers $User -API $APINAME -message "Permissions check failed: $($ErrorMessage.NormalizedError) " -Sev 'Error' -LogData $ErrorMessage
159159
$ErrorMessages.Add("We could not connect to the API to retrieve the permissions. There might be a problem with the secure application model configuration. The returned error is: $($ErrorMessage.NormalizedError)") | Out-Null
160+
161+
try {
162+
$MFAServicePolicy = New-GraphGetRequest -uri 'https://graph.microsoft.com/beta/policies/mfaServicePolicy' -tenantid $env:TenantID -AsApp $true -NoAuthCheck $true
163+
if ($MFAServicePolicy.rememberMfaOnTrustedDevice.isEnabled -eq $true -and $MFAServicePolicy.rememberMfaOnTrustedDevice.allowedNumberOfDays -gt 0) {
164+
$ErrorMessages.Add("MFA Service Policy has a session lifetime of $($MFAServicePolicy.rememberMfaOnTrustedDevice.allowedNumberOfDays) days. This may cause athentication issues for your service account.") | Out-Null
165+
$Links.Add([PSCustomObject]@{
166+
Text = 'Troubleshooting'
167+
Href = 'https://docs.cipp.app/troubleshooting/troubleshooting#multi-factor-authentication-troubleshooting'
168+
}
169+
) | Out-Null
170+
}
171+
} catch {}
172+
160173
$Success = $false
161174
}
162175

0 commit comments

Comments
 (0)