File tree Expand file tree Collapse file tree
Modules/CIPPCore/Public/GraphHelper Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -67,8 +67,15 @@ function Get-GraphToken {
6767 $AppCache = Get-CIPPAzDataTableEntity @ConfigTable - Filter $Filter
6868 # force auth update is appId is not the same as the one in the environment variable.
6969 if ($AppCache.ApplicationId -and $env: ApplicationID -ne $AppCache.ApplicationId ) {
70- Write-Host " Setting environment variable ApplicationID to $ ( $AppCache.ApplicationId ) "
71- $CIPPAuth = Get-CIPPAuthentication
70+ $CIPPAuth = Get-CIPPAuthentication # reload creds from KV (source of truth)
71+ if ($env: ApplicationID -and $env: ApplicationID -ne $AppCache.ApplicationId ) {
72+ # KV and AppCache genuinely diverged — reconcile the marker to KV so we
73+ # don't reload on every subsequent token call.
74+ Write-Host " AppCache ApplicationId ($ ( $AppCache.ApplicationId ) ) differs from KV ($env: ApplicationID ); reconciling AppCache."
75+ $null = Add-CIPPAzDataTableEntity @ConfigTable - Entity @ {
76+ PartitionKey = ' AppCache' ; RowKey = ' AppCache' ; ApplicationId = " $env: ApplicationID "
77+ } - Force
78+ }
7279 }
7380 $refreshToken = $env: RefreshToken
7481 # Get list of tenants that have 'directTenant' set to true
You can’t perform that action at this time.
0 commit comments