Skip to content

Commit d3e781a

Browse files
added appid detection to prevent cache hit
1 parent b965f1f commit d3e781a

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Setup/Invoke-ExecCreateSAMApp.ps1

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,14 @@ Function Invoke-ExecCreateSAMApp {
8484
Write-Information ($Secret | ConvertTo-Json -Depth 5)
8585
Add-CIPPAzDataTableEntity @DevSecretsTable -Entity $Secret -Force
8686
} else {
87+
$ConfigTable = Get-CippTable -tablename 'Config'
88+
#update the ConfigTable with the latest appId, for caching compare.
89+
$NewConfig = @{
90+
PartitionKey = 'AppCache'
91+
RowKey = 'AppCache'
92+
ApplicationId = $AppId.appId
93+
}
94+
Set-CIPPAzDataTableEntity @ConfigTable -Entity $NewConfig -Force | Out-Null
8795
Set-AzKeyVaultSecret -VaultName $kv -Name 'tenantid' -SecretValue (ConvertTo-SecureString -String $TenantId -AsPlainText -Force)
8896
Set-AzKeyVaultSecret -VaultName $kv -Name 'applicationid' -SecretValue (ConvertTo-SecureString -String $Appid.appId -AsPlainText -Force)
8997
Set-AzKeyVaultSecret -VaultName $kv -Name 'applicationsecret' -SecretValue (ConvertTo-SecureString -String $AppPassword -AsPlainText -Force)

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ function Get-GraphToken($tenantid, $scope, $AsApp, $AppID, $AppSecret, $refreshT
66
if (!$scope) { $scope = 'https://graph.microsoft.com/.default' }
77

88
if (!$env:SetFromProfile) { $CIPPAuth = Get-CIPPAuthentication; Write-Host 'Could not get Refreshtoken from environment variable. Reloading token.' }
9+
$ConfigTable = Get-CippTable -tablename 'Config'
10+
$Filter = "PartitionKey eq 'AppCache' and RowKey eq 'AppCache'"
11+
$AppCache = Get-CIPPAzDataTableEntity @ConfigTable -Filter $Filter
12+
#force auth update is appId is not the same as the one in the environment variable.
13+
if ($AppCache.ApplicationId -and $env:ApplicationID -ne $AppCache.ApplicationId) {
14+
Write-Host "Setting environment variable ApplicationID to $($AppCache.ApplicationId)"
15+
$CIPPAuth = Get-CIPPAuthentication
16+
}
17+
918
#If the $env:<$tenantid> is set, use that instead of the refreshtoken for all tenants.
1019
$refreshToken = $env:RefreshToken
1120
if (!$tenantid) { $tenantid = $env:TenantID }

0 commit comments

Comments
 (0)