Skip to content

Commit 27e432e

Browse files
authored
Merge pull request #268 from KelvinTegelaar/dev
[pull] dev from KelvinTegelaar:dev
2 parents 704d584 + 3af3902 commit 27e432e

File tree

5 files changed

+24
-6
lines changed

5 files changed

+24
-6
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Function Invoke-ExecAddTenant {
55
.FUNCTIONALITY
66
Entrypoint,AnyTenant
77
.ROLE
8-
CIPP.AppSettings.ReadWrite.
8+
CIPP.AppSettings.ReadWrite
99
#>
1010
[CmdletBinding()]
1111
param($Request, $TriggerMetadata)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Function Invoke-ExecCombinedSetup {
55
.FUNCTIONALITY
66
Entrypoint,AnyTenant
77
.ROLE
8-
CIPP.AppSettings.ReadWrite.
8+
CIPP.AppSettings.ReadWrite
99
#>
1010
[CmdletBinding()]
1111
param($Request, $TriggerMetadata)

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Function Invoke-ExecCreateSAMApp {
55
.FUNCTIONALITY
66
Entrypoint,AnyTenant
77
.ROLE
8-
CIPP.AppSettings.ReadWrite.
8+
CIPP.AppSettings.ReadWrite
99
#>
1010
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')]
1111
[CmdletBinding()]
@@ -84,10 +84,19 @@ Function Invoke-ExecCreateSAMApp {
8484
Write-Information ($Secret | ConvertTo-Json -Depth 5)
8585
Add-CIPPAzDataTableEntity @DevSecretsTable -Entity $Secret -Force
8686
} else {
87+
8788
Set-AzKeyVaultSecret -VaultName $kv -Name 'tenantid' -SecretValue (ConvertTo-SecureString -String $TenantId -AsPlainText -Force)
8889
Set-AzKeyVaultSecret -VaultName $kv -Name 'applicationid' -SecretValue (ConvertTo-SecureString -String $Appid.appId -AsPlainText -Force)
8990
Set-AzKeyVaultSecret -VaultName $kv -Name 'applicationsecret' -SecretValue (ConvertTo-SecureString -String $AppPassword -AsPlainText -Force)
9091
}
92+
$ConfigTable = Get-CippTable -tablename 'Config'
93+
#update the ConfigTable with the latest appId, for caching compare.
94+
$NewConfig = @{
95+
PartitionKey = 'AppCache'
96+
RowKey = 'AppCache'
97+
ApplicationId = $AppId.appId
98+
}
99+
Add-CIPPAzDataTableEntity @ConfigTable -Entity $NewConfig -Force | Out-Null
91100
$Results = @{'message' = "Succesfully $state the application registration. The application ID is $($AppId.appid). You may continue to the next step."; severity = 'success' }
92101
}
93102

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Function Invoke-ExecUpdateRefreshToken {
55
.FUNCTIONALITY
66
Entrypoint,AnyTenant
77
.ROLE
8-
CIPP.AppSettings.ReadWrite.
8+
CIPP.AppSettings.ReadWrite
99
#>
1010
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')]
1111
[CmdletBinding()]
@@ -29,7 +29,7 @@ Function Invoke-ExecUpdateRefreshToken {
2929
}
3030
Add-CIPPAzDataTableEntity @DevSecretsTable -Entity $Secret -Force
3131
} else {
32-
if ($env:ApplicationId -eq $Request.body.tenantId) {
32+
if ($env:TenantID -eq $Request.body.tenantId) {
3333
Set-AzKeyVaultSecret -VaultName $kv -Name 'RefreshToken' -SecretValue (ConvertTo-SecureString -String $Request.body.refreshtoken -AsPlainText -Force)
3434
} else {
3535
$name = $Request.body.tenantId -replace '-', '_'

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,16 @@ 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-
#If the $env:<$tenantid> is set, use that instead of the refreshtoken for all tenants.
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+
Write-Host "My appId pre-launch is $($env:ApplicationID) and the one in the cache is $($AppCache.ApplicationId)"
14+
if ($AppCache.ApplicationId -and $env:ApplicationID -ne $AppCache.ApplicationId) {
15+
Write-Host "Setting environment variable ApplicationID to $($AppCache.ApplicationId)"
16+
$CIPPAuth = Get-CIPPAuthentication
17+
}
18+
Write-Host "My appId post-launch is $($env:ApplicationID) and the one in the cache is $($AppCache.ApplicationId)"
1019
$refreshToken = $env:RefreshToken
1120
if (!$tenantid) { $tenantid = $env:TenantID }
1221
#Get list of tenants that have 'directTenant' set to true

0 commit comments

Comments
 (0)