You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(auth): resolve domain TenantID to GUID on load
If the TenantID secret is set to a domain name instead of a GUID, resolve it via the OpenID metadata endpoint and update the stored secret (DevSecrets table or Key Vault) so subsequent loads use the GUID directly.
Synced from CyberDrain/CIPP@6d65d86
throw"OpenID metadata for '$StoredTenantID' did not contain a tenant GUID (issuer: $($OpenIdConfig.issuer))"
42
+
}
43
+
$env:TenantID=$ResolvedTenantID
44
+
Write-LogMessage-message "The TenantID secret is set to domain name '$StoredTenantID' - resolved to tenant GUID $ResolvedTenantID."-Sev 'Warning'-API 'CIPP Authentication'
45
+
46
+
# Fix the stored secret so every future load gets the GUID directly.
47
+
# Best-effort: this session already has the resolved value.
Write-LogMessage-message "Updated the TenantID in the DevSecrets table from '$StoredTenantID' to tenant GUID $ResolvedTenantID."-Sev 'Info'-API 'CIPP Authentication'
53
+
} catch {
54
+
Write-LogMessage-message 'Could not update the TenantID in the DevSecrets table - it will be re-resolved on every authentication load.'-Sev 'Warning'-API 'CIPP Authentication'-LogData (Get-CippException-Exception $_)
Write-LogMessage-message "Updated the 'TenantID' Key Vault secret from '$StoredTenantID' to tenant GUID $ResolvedTenantID."-Sev 'Info'-API 'CIPP Authentication'
60
+
} catch {
61
+
Write-LogMessage-message "Could not update the 'TenantID' Key Vault secret to the tenant GUID - it will be re-resolved on every authentication load until the secret is updated manually."-Sev 'Warning'-API 'CIPP Authentication'-LogData (Get-CippException-Exception $_)
62
+
}
63
+
}
64
+
} catch {
65
+
Write-LogMessage-message "The TenantID secret ('$StoredTenantID') is not a GUID and could not be resolved to one. API integrations may misbehave until the 'tenantid' Key Vault secret is set to the tenant GUID."-Sev 'Error'-API 'CIPP Authentication'-LogData (Get-CippException-Exception $_)
66
+
}
67
+
}
68
+
29
69
# Set before certificate handling: Update-CIPPSAMCertificate goes through
30
70
# Get-GraphToken, which re-enters this function when SetFromProfile is unset
31
71
$env:SetFromProfile=$true
@@ -34,7 +74,7 @@ function Get-CIPPAuthentication {
34
74
# when it does not exist yet. Non-fatal: auth must succeed even when certificate
35
75
# handling fails; the weekly token update retries provisioning.
36
76
try {
37
-
if ($env:AzureWebJobsStorage-eq'UseDevelopmentStorage=true'-or$env:NonLocalHostAzurite-eq'true') {
0 commit comments