Skip to content

Commit dd9643f

Browse files
committed
Add support for QR code and fix headers param
1 parent 22bd356 commit dd9643f

2 files changed

Lines changed: 22 additions & 17 deletions

File tree

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tenant/Administration/Invoke-SetAuthMethod.ps1

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,23 @@ function Invoke-SetAuthMethod {
55
.ROLE
66
Tenant.Administration.ReadWrite
77
#>
8-
Param(
9-
$Request,
10-
$TriggerMetadata
11-
)
8+
Param($Request, $TriggerMetadata)
129

13-
$APIName = "Set Authentication Policy"
14-
$state = if ($Request.Body.state -eq 'enabled') { $true } else { $false }
15-
$Tenantfilter = $Request.Body.TenantFilter
10+
$APIName = $Request.Params.CIPPEndpoint
11+
$State = if ($Request.Body.state -eq 'enabled') { $true } else { $false }
12+
$TenantFilter = $Request.Body.tenantFilter
1613

1714
try {
18-
Set-CIPPAuthenticationPolicy -Tenant $Tenantfilter -APIName $APIName -AuthenticationMethodId $($Request.Body.Id) -Enabled $state
15+
$Result = Set-CIPPAuthenticationPolicy -Tenant $TenantFilter -APIName $APIName -AuthenticationMethodId $($Request.Body.Id) -Enabled $State -Headers $Request.Headers
1916
$StatusCode = [HttpStatusCode]::OK
20-
$SuccessMessage = "Authentication Policy for $($Request.Body.Id) has been set to $state"
2117
} catch {
22-
$ErrorMsg = Get-NormalizedError -message $($_.Exception.Message)
23-
$SuccessMessage = "Function Error: $($_.InvocationInfo.ScriptLineNumber) - $ErrorMsg"
24-
$StatusCode = [HttpStatusCode]::BadRequest
18+
$Result = $_
19+
$StatusCode = [HttpStatusCode]::Forbidden
2520
}
2621

2722
# Associate values to output bindings by calling 'Push-OutputBinding'.
2823
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
2924
StatusCode = $StatusCode
30-
Body = [pscustomobject]@{'Results' = "$SuccessMessage" }
25+
Body = [pscustomobject]@{'Results' = "$Result" }
3126
})
32-
}
27+
}

Modules/CIPPCore/Public/Set-CIPPAuthenticationPolicy.ps1

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@ function Set-CIPPAuthenticationPolicy {
22
[CmdletBinding(SupportsShouldProcess = $true)]
33
param(
44
[Parameter(Mandatory = $true)]$Tenant,
5-
[Parameter(Mandatory = $true)][ValidateSet('FIDO2', 'MicrosoftAuthenticator', 'SMS', 'TemporaryAccessPass', 'HardwareOATH', 'softwareOath', 'Voice', 'Email', 'x509Certificate')]$AuthenticationMethodId,
5+
[Parameter(Mandatory = $true)][ValidateSet('FIDO2', 'MicrosoftAuthenticator', 'SMS', 'TemporaryAccessPass', 'HardwareOATH', 'softwareOath', 'Voice', 'Email', 'x509Certificate', 'QRCodePin')]$AuthenticationMethodId,
66
[Parameter(Mandatory = $true)][bool]$Enabled, # true = enabled or false = disabled
77
$MicrosoftAuthenticatorSoftwareOathEnabled,
88
$TAPMinimumLifetime = 60, #Minutes
99
$TAPMaximumLifetime = 480, #minutes
1010
$TAPDefaultLifeTime = 60, #minutes
1111
$TAPDefaultLength = 8, #TAP password generated length in chars
1212
$TAPisUsableOnce = $true,
13+
[Parameter()][ValidateRange(1, 395)]$QRCodeLifetimeInDays = 365,
14+
[Parameter()][ValidateRange(8, 20)]$QRCodePinLength = 8,
1315
$APIName = 'Set Authentication Policy',
1416
$Headers
1517
)
@@ -103,6 +105,14 @@ function Set-CIPPAuthenticationPolicy {
103105
'x509Certificate' {
104106
# Nothing special to do here
105107
}
108+
109+
# QR code
110+
'QRCodePin' {
111+
if ($State -eq 'enabled') {
112+
$CurrentInfo.pinLength = $QRCodePinLength
113+
$CurrentInfo.standardQRCodeLifetimeInDays = $QRCodeLifetimeInDays
114+
}
115+
}
106116
Default {
107117
Write-LogMessage -headers $Headers -API $APIName -tenant $Tenant -message "Somehow you hit the default case with an input of $AuthenticationMethodId . You probably made a typo in the input for AuthenticationMethodId. It`'s case sensitive." -sev Error
108118
return "Somehow you hit the default case with an input of $AuthenticationMethodId . You probably made a typo in the input for AuthenticationMethodId. It`'s case sensitive."
@@ -112,14 +122,14 @@ function Set-CIPPAuthenticationPolicy {
112122
try {
113123
if ($PSCmdlet.ShouldProcess($AuthenticationMethodId, "Set state to $State $OptionalLogMessage")) {
114124
# Convert body to JSON and send request
115-
$null = New-GraphPostRequest -tenantid $Tenant -Uri "https://graph.microsoft.com/beta/policies/authenticationmethodspolicy/authenticationMethodConfigurations/$AuthenticationMethodId" -Type patch -Body ($CurrentInfo | ConvertTo-Json -Compress -Depth 10) -ContentType 'application/json'
125+
$null = New-GraphPostRequest -tenantid $Tenant -Uri "https://graph.microsoft.com/beta/policies/authenticationmethodspolicy/authenticationMethodConfigurations/$AuthenticationMethodId" -Type PATCH -Body (ConvertTo-Json -InputObject $CurrentInfo -Compress -Depth 10) -ContentType 'application/json'
116126
Write-LogMessage -headers $Headers -API $APIName -tenant $Tenant -message "Set $AuthenticationMethodId state to $State $OptionalLogMessage" -sev Info
117127
}
118128
return "Set $AuthenticationMethodId state to $State $OptionalLogMessage"
119129

120130
} catch {
121131
$ErrorMessage = Get-CippException -Exception $_
122132
Write-LogMessage -headers $Headers -API $APIName -tenant $Tenant -message "Failed to $State $AuthenticationMethodId Support: $ErrorMessage" -sev Error -LogData $ErrorMessage
123-
return "Failed to $State $AuthenticationMethodId Support. Error: $($ErrorMessage.NormalizedError)"
133+
throw "Failed to $State $AuthenticationMethodId Support. Error: $($ErrorMessage.NormalizedError)"
124134
}
125135
}

0 commit comments

Comments
 (0)