Skip to content

Commit 17203b2

Browse files
committed
Change auth settings retrieval order in Get-CippApiAuth
Now retrieves authentication settings via Azure REST API first, falling back to the WEBSITE_AUTH_V2_CONFIG_JSON environment variable only if the REST call fails. This improves reliability by prioritizing live configuration data.
1 parent a7da0de commit 17203b2

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

Modules/CIPPCore/Public/Authentication/Get-CippApiAuth.ps1

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,15 @@ function Get-CippApiAuth {
44
[string]$FunctionAppName
55
)
66

7-
if ($env:WEBSITE_AUTH_V2_CONFIG_JSON) {
8-
$AuthSettings = $env:WEBSITE_AUTH_V2_CONFIG_JSON | ConvertFrom-Json -ErrorAction SilentlyContinue
9-
}
7+
$SubscriptionId = Get-CIPPAzFunctionAppSubId
108

11-
if (-not $AuthSettings) {
12-
$SubscriptionId = Get-CIPPAzFunctionAppSubId
9+
# Get auth settings via REST
10+
$uri = "https://management.azure.com/subscriptions/$SubscriptionId/resourceGroups/$RGName/providers/Microsoft.Web/sites/$($FunctionAppName)/config/authsettingsV2/list?api-version=2020-06-01"
11+
$response = New-CIPPAzRestRequest -Uri $uri -Method POST -ErrorAction Stop
12+
$AuthSettings = $response.properties
1313

14-
# Get auth settings via REST
15-
$uri = "https://management.azure.com/subscriptions/$SubscriptionId/resourceGroups/$RGName/providers/Microsoft.Web/sites/$($FunctionAppName)/config/authsettingsV2/list?api-version=2020-06-01"
16-
$response = New-CIPPAzRestRequest -Uri $uri -Method POST -ErrorAction Stop
17-
$AuthSettings = $response.properties
14+
if (!$AuthSettings -and $env:WEBSITE_AUTH_V2_CONFIG_JSON) {
15+
$AuthSettings = $env:WEBSITE_AUTH_V2_CONFIG_JSON | ConvertFrom-Json -ErrorAction SilentlyContinue
1816
}
1917

2018
if ($AuthSettings) {

0 commit comments

Comments
 (0)