Skip to content

Commit f9d3372

Browse files
authored
Merge pull request #1093 from KelvinTegelaar/dev
[pull] dev from KelvinTegelaar:dev
2 parents d5c6ac1 + 610ec61 commit f9d3372

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

Modules/CIPPCore/Public/GraphHelper/Get-GraphToken.ps1

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)