-
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.
Merge pull request #1184 from kris6673/per-user-mfa-entrypoint
Add Per User MFA endpoint and improve null comparisons
- Loading branch information
Showing
2 changed files
with
52 additions
and
2 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) | ||
}) | ||
|
||
|
||
} |
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