Skip to content

Commit

Permalink
Merge pull request #62 from KelvinTegelaar/dev
Browse files Browse the repository at this point in the history
[pull] dev from KelvinTegelaar:dev
  • Loading branch information
pull[bot] authored Feb 7, 2025
2 parents 40fae4b + 653b356 commit 20f392b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 18 deletions.
38 changes: 25 additions & 13 deletions Modules/CIPPCore/Public/Authentication/Set-CippApiAuth.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,33 @@ function Set-CippApiAuth {
"api://$ClientId"
}

if (!$AllowedAudiences) { $AllowedAudiences = @() }
if (!$ClientIds) { $ClientIds = @() }

# Set auth settings
$AuthSettings.properties.identityProviders.azureActiveDirectory = @{
registration = @{
clientId = $ClientIds[0] ?? $ClientIds
openIdIssuer = "https://sts.windows.net/$TenantID/v2.0"
}
validation = @{
allowedAudiences = @($AllowedAudiences)
defaultAuthorizationPolicy = @{
allowedApplications = @($ClientIds)

if (($ClientIds | Measure-Object).Count -gt 0) {
$AuthSettings.properties.identityProviders.azureActiveDirectory = @{
enabled = $true
registration = @{
clientId = $ClientIds[0] ?? $ClientIds
openIdIssuer = "https://sts.windows.net/$TenantID/v2.0"
}
validation = @{
allowedAudiences = @($AllowedAudiences)
defaultAuthorizationPolicy = @{
allowedApplications = @($ClientIds)
}
}
}
} else {
$AuthSettings.properties.identityProviders.azureActiveDirectory = @{
enabled = $false
registration = @{}
validation = @{}
}
}

$AuthSettings.properties.globalValidation = @{
unauthenticatedClientAction = 'Return401'
}
Expand All @@ -47,14 +61,12 @@ function Set-CippApiAuth {
}
}

Write-Information ($AuthSettings | ConvertTo-Json -Depth 10)

if ($PSCmdlet.ShouldProcess('Update auth settings')) {
# Update auth settings
Invoke-AzRestMethod -Uri "https://management.azure.com/subscriptions/$SubscriptionId/resourceGroups/$RGName/providers/Microsoft.Web/sites/$($FunctionAppName)/config/authsettingsV2?api-version=2020-06-01" -Method PUT -Payload ($AuthSettings | ConvertTo-Json -Depth 10)
$null = Invoke-AzRestMethod -Uri "https://management.azure.com/subscriptions/$SubscriptionId/resourceGroups/$RGName/providers/Microsoft.Web/sites/$($FunctionAppName)/config/authsettingsV2?api-version=2020-06-01" -Method PUT -Payload ($AuthSettings | ConvertTo-Json -Depth 10)
}

if ($PSCmdlet.ShouldProcess('Update allowed tenants')) {
Update-AzFunctionAppSetting -Name $FunctionAppName -ResourceGroupName $RGName -AppSetting @{ 'WEBSITE_AUTH_AAD_ALLOWED_TENANTS' = $TenantId }
$null = Update-AzFunctionAppSetting -Name $FunctionAppName -ResourceGroupName $RGName -AppSetting @{ 'WEBSITE_AUTH_AAD_ALLOWED_TENANTS' = $TenantId }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ Function Invoke-ExecAddTrustedIP {

$Table = Get-CippTable -tablename 'trustedIps'
Add-CIPPAzDataTableEntity @Table -Entity @{
PartitionKey = $request.query.tenantfilter
RowKey = $Request.query.ip
state = $request.query.State
PartitionKey = $Request.Body.tenantfilter
RowKey = $Request.Body.IP
state = $Request.Body.State
} -Force

Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = [HttpStatusCode]::OK
Body = @{ results = "Added $($Request.query.ip) to database with state $($Request.query.state) for $($Request.query.tenantfilter)" }
Body = @{ results = "Added $($Request.Body.IP) to database with state $($Request.Body.State) for $($Request.Body.tenantfilter)" }
})
}
}

0 comments on commit 20f392b

Please sign in to comment.