Skip to content

Commit 2b5360e

Browse files
committed
Set refresh token as environment variable after update
After updating the refresh token, immediately set it as an environment variable to make it available for subsequent operations. This applies to both the main tenant and additional tenants, ensuring the new token is accessible without delay.
1 parent 09d5c7b commit 2b5360e

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,35 @@ function Invoke-ExecUpdateRefreshToken {
2121

2222
if ($env:TenantID -eq $Request.body.tenantId) {
2323
$Secret | Add-Member -MemberType NoteProperty -Name 'RefreshToken' -Value $Request.body.refreshtoken -Force
24+
# Set environment variable to make it immediately available
25+
Set-Item -Path env:RefreshToken -Value $Request.body.refreshtoken -Force
2426
} else {
2527
Write-Host "$($env:TenantID) does not match $($Request.body.tenantId)"
2628
$name = $Request.body.tenantId -replace '-', '_'
2729
$secret | Add-Member -MemberType NoteProperty -Name $name -Value $Request.body.refreshtoken -Force
30+
# Set environment variable to make it immediately available
31+
Set-Item -Path env:$name -Value $Request.body.refreshtoken -Force
2832
}
2933
Add-CIPPAzDataTableEntity @DevSecretsTable -Entity $Secret -Force
3034
} else {
3135
if ($env:TenantID -eq $Request.body.tenantId) {
3236
Set-CippKeyVaultSecret -VaultName $kv -Name 'RefreshToken' -SecretValue (ConvertTo-SecureString -String $Request.body.refreshtoken -AsPlainText -Force)
37+
# Set environment variable to make it immediately available
38+
Set-Item -Path env:RefreshToken -Value $Request.body.refreshtoken -Force
39+
$InstanceId = Start-UpdatePermissionsOrchestrator #start the CPV refresh immediately while wizard still runs.
3340
} else {
3441
Write-Host "$($env:TenantID) does not match $($Request.body.tenantId) - we're adding a new secret for the tenant."
3542
$name = $Request.body.tenantId
3643
try {
3744
Set-CippKeyVaultSecret -VaultName $kv -Name $name -SecretValue (ConvertTo-SecureString -String $Request.body.refreshtoken -AsPlainText -Force)
45+
# Set environment variable to make it immediately available
46+
Set-Item -Path env:$name -Value $Request.body.refreshtoken -Force
3847
} catch {
3948
Write-Host "Failed to set secret $name in KeyVault. $($_.Exception.Message)"
4049
throw $_
4150
}
4251
}
4352
}
44-
$InstanceId = Start-UpdatePermissionsOrchestrator #start the CPV refresh immediately while wizard still runs.
4553

4654
if ($request.body.tenantId -eq $env:TenantID) {
4755
$TenantName = 'your partner tenant'

0 commit comments

Comments
 (0)