@@ -15,61 +15,58 @@ function Invoke-ExecUpdateRefreshToken {
1515 # Handle refresh token update
1616 # make sure we get the latest authentication:
1717 $auth = Get-CIPPAuthentication
18+ $IsPartnerTenant = $env: TenantID -eq $Request.body.tenantId
19+
1820 if ($env: AzureWebJobsStorage -eq ' UseDevelopmentStorage=true' -or $env: NonLocalHostAzurite -eq ' true' ) {
1921 $DevSecretsTable = Get-CIPPTable - tablename ' DevSecrets'
2022 $Secret = Get-CIPPAzDataTableEntity @DevSecretsTable - Filter " PartitionKey eq 'Secret' and RowKey eq 'Secret'"
21-
22- if ($env: TenantID -eq $Request.body.tenantId ) {
23+ if ($IsPartnerTenant ) {
2324 $Secret | Add-Member - MemberType NoteProperty - Name ' RefreshToken' - Value $Request.body.refreshtoken - Force
24- # Set environment variable to make it immediately available
2525 Set-Item - Path env:RefreshToken - Value $Request.body.refreshtoken - Force
2626 } else {
27- Write-Host " $ ( $env: TenantID ) does not match $ ( $Request.body.tenantId ) "
2827 $name = $Request.body.tenantId -replace ' -' , ' _'
29- $secret | Add-Member - MemberType NoteProperty - Name $name - Value $Request.body.refreshtoken - Force
30- # Set environment variable to make it immediately available
28+ $Secret | Add-Member - MemberType NoteProperty - Name $name - Value $Request.body.refreshtoken - Force
3129 Set-Item - Path env:$name - Value $Request.body.refreshtoken - Force
3230 }
3331 Add-CIPPAzDataTableEntity @DevSecretsTable - Entity $Secret - Force
3432 } else {
35- if ($env: TenantID -eq $Request .body.tenantId ) {
33+ if ($IsPartnerTenant ) {
3634 Set-CippKeyVaultSecret - VaultName $kv - Name ' RefreshToken' - SecretValue (ConvertTo-SecureString - String $Request.body.refreshtoken - AsPlainText - Force)
37- # Set environment variable to make it immediately available
3835 Set-Item - Path env:RefreshToken - Value $Request.body.refreshtoken - Force
39-
40- # Trigger CPV refresh for partner tenant only
41- try {
42- $Queue = New-CippQueueEntry - Name ' Update Permissions - Partner Tenant' - TotalTasks 1
43- $TenantBatch = @ ([PSCustomObject ]@ {
44- defaultDomainName = ' PartnerTenant'
45- customerId = $env: TenantID
46- displayName = ' *Partner Tenant'
47- FunctionName = ' UpdatePermissionsQueue'
48- QueueId = $Queue.RowKey
49- })
50- $InputObject = [PSCustomObject ]@ {
51- OrchestratorName = ' UpdatePermissionsOrchestrator'
52- Batch = @ ($TenantBatch )
53- }
54- Start-CIPPOrchestrator - InputObject $InputObject
55- Write-Information ' Started permissions update orchestrator for Partner Tenant'
56- } catch {
57- Write-Warning " Failed to start permissions orchestrator: $ ( $_.Exception.Message ) "
58- }
5936 } else {
60- Write-Host " $ ( $env: TenantID ) does not match $ ( $Request.body.tenantId ) - we're adding a new secret for the tenant."
37+ Write-Information " $ ( $env: TenantID ) does not match $ ( $Request.body.tenantId ) - adding a new secret for the tenant."
6138 $name = $Request.body.tenantId
6239 try {
6340 Set-CippKeyVaultSecret - VaultName $kv - Name $name - SecretValue (ConvertTo-SecureString - String $Request.body.refreshtoken - AsPlainText - Force)
64- # Set environment variable to make it immediately available
6541 Set-Item - Path env:$name - Value $Request.body.refreshtoken - Force
6642 } catch {
67- Write-Host " Failed to set secret $name in KeyVault. $ ( $_.Exception.Message ) "
43+ Write-Information " Failed to set secret $name in KeyVault. $ ( $_.Exception.Message ) "
6844 throw $_
6945 }
7046 }
7147 }
7248
49+ if ($IsPartnerTenant ) {
50+ try {
51+ $Queue = New-CippQueueEntry - Name ' Update Permissions - Partner Tenant' - TotalTasks 1
52+ $TenantBatch = @ ([PSCustomObject ]@ {
53+ defaultDomainName = ' PartnerTenant'
54+ customerId = $env: TenantID
55+ displayName = ' *Partner Tenant'
56+ FunctionName = ' UpdatePermissionsQueue'
57+ QueueId = $Queue.RowKey
58+ })
59+ $InputObject = [PSCustomObject ]@ {
60+ OrchestratorName = ' UpdatePermissionsOrchestrator'
61+ Batch = @ ($TenantBatch )
62+ }
63+ Start-CIPPOrchestrator - InputObject $InputObject
64+ Write-Information ' Started permissions update orchestrator for Partner Tenant'
65+ } catch {
66+ Write-Warning " Failed to start permissions orchestrator: $ ( $_.Exception.Message ) "
67+ }
68+ }
69+
7370 if ($request.body.tenantId -eq $env: TenantID ) {
7471 $TenantName = ' your partner tenant'
7572 } else {
0 commit comments