From af64f8f00851c7c4e901109228a17c079b287f57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristian=20Kj=C3=A6rg=C3=A5rd?= Date: Wed, 13 Nov 2024 19:15:54 +0100 Subject: [PATCH 1/3] flip null comparisons --- Modules/CIPPCore/Public/Get-CIPPMFAState.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Modules/CIPPCore/Public/Get-CIPPMFAState.ps1 b/Modules/CIPPCore/Public/Get-CIPPMFAState.ps1 index 712301b3dc77..9cb9e6914f9c 100644 --- a/Modules/CIPPCore/Public/Get-CIPPMFAState.ps1 +++ b/Modules/CIPPCore/Public/Get-CIPPMFAState.ps1 @@ -92,9 +92,9 @@ function Get-CIPPMFAState { } } - $PerUser = if ($PerUserMFAState -eq $null) { $null } else { ($PerUserMFAState | Where-Object -Property UserPrincipalName -EQ $_.UserPrincipalName).PerUserMFAState } + $PerUser = if ($null -eq $PerUserMFAState) { $null } else { ($PerUserMFAState | Where-Object -Property UserPrincipalName -EQ $_.UserPrincipalName).PerUserMFAState } - $MFARegUser = if (($MFARegistration | Where-Object -Property UserPrincipalName -EQ $_.userPrincipalName).isMFARegistered -eq $null) { $false } else { ($MFARegistration | Where-Object -Property UserPrincipalName -EQ $_.userPrincipalName) } + $MFARegUser = if ($null -eq ($MFARegistration | Where-Object -Property UserPrincipalName -EQ $_.userPrincipalName).isMFARegistered) { $false } else { ($MFARegistration | Where-Object -Property UserPrincipalName -EQ $_.userPrincipalName) } [PSCustomObject]@{ Tenant = $TenantFilter From ed55e69a06ccb7b687beae87f1e8382134ba8d8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristian=20Kj=C3=A6rg=C3=A5rd?= Date: Wed, 13 Nov 2024 19:33:04 +0100 Subject: [PATCH 2/3] Add Invoke-ListPerUserMFA function for retrieving MFA state per user --- .../Users/Invoke-ListPerUserMFA.ps1 | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Identity/Administration/Users/Invoke-ListPerUserMFA.ps1 diff --git a/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Identity/Administration/Users/Invoke-ListPerUserMFA.ps1 b/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Identity/Administration/Users/Invoke-ListPerUserMFA.ps1 new file mode 100644 index 000000000000..0d3f4c16d914 --- /dev/null +++ b/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Identity/Administration/Users/Invoke-ListPerUserMFA.ps1 @@ -0,0 +1,50 @@ +using namespace System.Net + +function Invoke-ListPerUserMFA { + <# + .FUNCTIONALITY + Entrypoint + .ROLE + Identity.User.Read + #> + [CmdletBinding()] + param($Request, $TriggerMetadata) + + $APIName = $TriggerMetadata.FunctionName + $User = $request.headers.'x-ms-client-principal' + Write-LogMessage -user $User -API $APINAME -message 'Accessed this API' -Sev 'Debug' + + # Write to the Azure Functions log stream. + Write-Host 'PowerShell HTTP trigger function processed a request.' + + # Parse query parameters + $Tenant = $Request.query.TenantFilter + try { + $AllUsers = [System.Convert]::ToBoolean($Request.query.allUsers) + } catch { + $AllUsers = $false + } + $UserId = $Request.query.userId + + # Get the MFA state for the user/all users + try { + if ($AllUsers -eq $true) { + $Results = Get-CIPPPerUserMFA -TenantFilter $Tenant -AllUsers $true + } else { + $Results = Get-CIPPPerUserMFA -TenantFilter $Tenant -userId $UserId + } + $StatusCode = [HttpStatusCode]::OK + } catch { + $ErrorMessage = Get-NormalizedError -Message $_.Exception.Message + $Results = "Failed to get MFA State for $UserId : $ErrorMessage" + $StatusCode = [HttpStatusCode]::Forbidden + } + + # Associate values to output bindings by calling 'Push-OutputBinding'. + Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{ + StatusCode = $StatusCode + Body = @($Results) + }) + + +} From 9784888da622e8dfee4a540e6a66de53a2acaf3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristian=20Kj=C3=A6rg=C3=A5rd?= Date: Wed, 13 Nov 2024 19:43:45 +0100 Subject: [PATCH 3/3] Whoops forgot camel casing --- .../Identity/Administration/Users/Invoke-ListPerUserMFA.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Identity/Administration/Users/Invoke-ListPerUserMFA.ps1 b/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Identity/Administration/Users/Invoke-ListPerUserMFA.ps1 index 0d3f4c16d914..39bbcd9bc268 100644 --- a/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Identity/Administration/Users/Invoke-ListPerUserMFA.ps1 +++ b/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Identity/Administration/Users/Invoke-ListPerUserMFA.ps1 @@ -18,7 +18,7 @@ function Invoke-ListPerUserMFA { Write-Host 'PowerShell HTTP trigger function processed a request.' # Parse query parameters - $Tenant = $Request.query.TenantFilter + $Tenant = $Request.query.tenantFilter try { $AllUsers = [System.Convert]::ToBoolean($Request.query.allUsers) } catch {