-
Notifications
You must be signed in to change notification settings - Fork 5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Invoke-ListPerUserMFA function for retrieving MFA state per user
- Loading branch information
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
...Public/Entrypoints/HTTP Functions/Identity/Administration/Users/Invoke-ListPerUserMFA.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
}) | ||
|
||
|
||
} |