Skip to content

Commit f6f95d9

Browse files
fix(auth): skip placeholder SAM credentials on fresh deploy
Fresh deployments carry template placeholder values (e.g. LongApplicationId, AppSecret) until the setup wizard completes. Previously these were treated as valid credentials, causing EasyAuth issuer reconciliation to rewrite a correctly configured issuer and break sign-in. Now placeholder values are detected and the instance is treated as unconfigured. Synced from CyberDrain/CIPP@77776c5
1 parent 5274c77 commit f6f95d9

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

Modules/CIPPCore/Public/Authentication/Initialize-CIPPAuth.ps1

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,19 @@ function Initialize-CIPPAuth {
3333
Write-Information "[Auth-Init] Credential source available (KV=$($AuthState.HasKeyVault), DevStorage=$IsDevStorage) — attempting SAM load"
3434
try {
3535
$Auth = Get-CIPPAuthentication
36-
if ($Auth -and $env:ApplicationID -and $env:TenantID) {
36+
# Fresh deployments carry the deployment template's placeholder secrets
37+
# until the setup wizard writes real ones — treat those as "no
38+
# credentials" or the EasyAuth issuer reconciliation below rewrites a
39+
# correctly configured issuer to .../tenantId/v2.0 and breaks sign-in.
40+
$PlaceholderPattern = '^(LongApplicationId|AppSecret|RefreshToken|tenantId)$'
41+
$HasPlaceholders = ($env:ApplicationID -match $PlaceholderPattern) -or ($env:TenantID -match $PlaceholderPattern)
42+
if ($Auth -and $env:ApplicationID -and $env:TenantID -and -not $HasPlaceholders) {
3743
$AuthState.HasSAMCredentials = $true
3844
$AuthState.NeedsSetup = $false
3945
$AuthState.IsConfigured = $true
4046
Write-Information "[Auth-Init] SAM credentials loaded (AppID: $($env:ApplicationID), TenantID: $($env:TenantID))"
47+
} elseif ($HasPlaceholders) {
48+
Write-Information '[Auth-Init] SAM secrets still hold deployment placeholder values — setup wizard has not been completed yet, treating as unconfigured'
4149
} else {
4250
Write-Information '[Auth-Init] SAM credential load returned but env vars not populated — credentials not available yet (expected on fresh deployment)'
4351
}

0 commit comments

Comments
 (0)