Skip to content

Commit 91f87d2

Browse files
authored
Merge pull request #772 from KelvinTegelaar/dev
[pull] dev from KelvinTegelaar:dev
2 parents fe87e8a + 7473508 commit 91f87d2

File tree

3 files changed

+31
-15
lines changed

3 files changed

+31
-15
lines changed

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,20 @@ function Invoke-SetAuthMethod {
1515
$State = if ($Request.Body.state -eq 'enabled') { $true } else { $false }
1616
$TenantFilter = $Request.Body.tenantFilter
1717
$AuthenticationMethodId = $Request.Body.Id
18-
18+
$GroupIds = $Request.Body.GroupIds
1919

2020
try {
21-
$Result = Set-CIPPAuthenticationPolicy -Tenant $TenantFilter -APIName $APIName -AuthenticationMethodId $AuthenticationMethodId -Enabled $State -Headers $Headers
21+
$Params = @{
22+
Tenant = $TenantFilter
23+
APIName = $APIName
24+
AuthenticationMethodId = $AuthenticationMethodId
25+
Enabled = $State
26+
Headers = $Headers
27+
}
28+
if ($GroupIds) {
29+
$Params.GroupIds = @($GroupIds)
30+
}
31+
$Result = Set-CIPPAuthenticationPolicy @Params
2232
$StatusCode = [HttpStatusCode]::OK
2333
} catch {
2434
$Result = $_.Exception.Message

Modules/CIPPCore/Public/New-CIPPGroup.ps1

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -77,20 +77,11 @@ function New-CIPPGroup {
7777
$null
7878
}
7979

80-
# Extract local part of username if exists and remove special characters for mailNickname
81-
if ($GroupObject.username -like '*@*') {
82-
$MailNickname = ($GroupObject.username -split '@')[0]
80+
# Determine if we should generate a mailNickname with a GUID, or use the username field
81+
if (-not $GroupObject.Username) {
82+
$MailNickname = (New-Guid).guid.substring(0, 10)
8383
} else {
84-
$MailNickname = $GroupObject.username
85-
}
86-
87-
# Remove forbidden characters per Microsoft 365 mailNickname requirements:
88-
# ASCII 0-127 only, excluding: @ () / [] ' ; : <> , SPACE and any non-ASCII
89-
$MailNickname = $MailNickname -replace "[@()\[\]/'`;:<>,\s]|[^\x00-\x7F]", ''
90-
91-
# Ensure max length of 64 characters
92-
if ($MailNickname.Length -gt 64) {
93-
$MailNickname = $MailNickname.Substring(0, 64)
84+
$MailNickname = $GroupObject.Username
9485
}
9586

9687
Write-LogMessage -API $APIName -tenant $TenantFilter -message "Creating group $($GroupObject.displayName) of type $NormalizedGroupType$(if ($NeedsEmail) { " with email $Email" })" -Sev Info

Modules/CIPPCore/Public/Set-CIPPAuthenticationPolicy.ps1

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ function Set-CIPPAuthenticationPolicy {
1010
$TAPDefaultLifeTime = 60, #minutes
1111
$TAPDefaultLength = 8, #TAP password generated length in chars
1212
$TAPisUsableOnce = $true,
13+
[Parameter()][string[]]$GroupIds,
1314
[Parameter()][ValidateRange(1, 395)]$QRCodeLifetimeInDays = 365,
1415
[Parameter()][ValidateRange(8, 20)]$QRCodePinLength = 8,
1516
$APIName = 'Set Authentication Policy',
@@ -118,6 +119,20 @@ function Set-CIPPAuthenticationPolicy {
118119
throw "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."
119120
}
120121
}
122+
123+
if ($PSBoundParameters.ContainsKey('GroupIds') -and $GroupIds) {
124+
$CurrentInfo.includeTargets = @(
125+
foreach ($id in $GroupIds ) {
126+
[pscustomobject]@{
127+
targetType = 'group'
128+
id = $id
129+
}
130+
}
131+
)
132+
$OptionalLogMessage += " and targeted groups set to $($CurrentInfo.includeTargets.id -join ', ')"
133+
}
134+
135+
121136
# Set state of the authentication method
122137
try {
123138
if ($PSCmdlet.ShouldProcess($AuthenticationMethodId, "Set state to $State $OptionalLogMessage")) {

0 commit comments

Comments
 (0)