Skip to content

Commit 49741ff

Browse files
committed
prevent missing refresh_token in claims
1 parent 615737a commit 49741ff

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ function Invoke-ExecAddTenant {
2222
# Check if tenant already exists
2323
$ExistingTenant = Get-CIPPAzDataTableEntity @TenantsTable -Filter "PartitionKey eq 'Tenants' and RowKey eq '$tenantId'"
2424

25-
if ($ExistingTenant) {
25+
if ($tenantId -eq $env:TenantID) {
26+
# If the tenant is the partner tenant, return an error because you cannot add the partner tenant as direct tenant
27+
$Results = @{'message' = 'You cannot add the partner tenant as a direct tenant.'; 'severity' = 'error'; 'state' = 'error' }
28+
Write-LogMessage -API 'Add-Tenant' -message "Attempted to add partner tenant $tenantId as direct tenant." -Sev 'Error'
29+
} elseif ($ExistingTenant) {
2630
# Update existing tenant
2731
$ExistingTenant.delegatedPrivilegeStatus = 'directTenant'
2832
Add-CIPPAzDataTableEntity @TenantsTable -Entity $ExistingTenant -Force | Out-Null

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function Get-GraphToken($tenantid, $scope, $AsApp, $AppID, $AppSecret, $refreshT
2121
$TenantsTable = Get-CippTable -tablename 'Tenants'
2222
$Filter = "PartitionKey eq 'Tenants' and delegatedPrivilegeStatus eq 'directTenant'"
2323
$ClientType = Get-CIPPAzDataTableEntity @TenantsTable -Filter $Filter | Where-Object { $_.customerId -eq $tenantid -or $_.defaultDomainName -eq $tenantid }
24-
if ($clientType.delegatedPrivilegeStatus -eq 'directTenant') {
24+
if ($tenantid -ne $env:TenantID -and $clientType.delegatedPrivilegeStatus -eq 'directTenant') {
2525
Write-Host "Using direct tenant refresh token for $($clientType.customerId)"
2626
$ClientRefreshToken = Get-Item -Path "env:\$($clientType.customerId)" -ErrorAction SilentlyContinue
2727
$refreshToken = $ClientRefreshToken.Value

0 commit comments

Comments
 (0)