Skip to content

Commit

Permalink
Merge branch 'interface-rewrite' of https://github.com/KelvinTegelaar…
Browse files Browse the repository at this point in the history
…/CIPP-API into interface-rewrite
  • Loading branch information
KelvinTegelaar committed Jan 2, 2025
2 parents 9de8728 + d0752dc commit 391da0d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ function Invoke-ExecServicePrincipals {
'appId' = $Request.Query.AppId
} | ConvertTo-Json -Compress
try {
$Results = New-GraphPostRequest -Uri 'https://graph.microsoft.com/beta/servicePrincipals' -tenantid $TenantFilter -type POST -body $Body -NoAuthCheck $true
$ServicePrincipal = New-GraphPostRequest -Uri 'https://graph.microsoft.com/beta/servicePrincipals' -tenantid $TenantFilter -type POST -body $Body -NoAuthCheck $true
$Results = "Created service principal for $($ServicePrincipal.displayName) ($($ServicePrincipal.appId))"
} catch {
$Results = "Unable to create service principal: $($_.Exception.Message)"
$Success = $false
Expand Down Expand Up @@ -55,6 +56,10 @@ function Invoke-ExecServicePrincipals {
'Success' = $Success
}

if ($ServicePrincipal) {
$Metadata.ServicePrincipal = $ServicePrincipal
}

if ($Request.Query.AppId) {
$Metadata.AppId = $Request.Query.AppId
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,35 @@ function Start-UpdateTokensTimer {

# Get the current universal time in the default string format.
$currentUTCtime = (Get-Date).ToUniversalTime()
try {
$Refreshtoken = (Get-GraphToken -ReturnRefresh $true).Refresh_token

$Refreshtoken = (Get-GraphToken -ReturnRefresh $true).Refresh_token

if ($env:AzureWebJobsStorage -eq 'UseDevelopmentStorage=true') {
$Table = Get-CIPPTable -tablename 'DevSecrets'
$Secret = Get-CIPPAzDataTableEntity @Table -Filter "PartitionKey eq 'Secret' and RowKey eq 'Secret'"
if ($Secret) {
$Secret.RefreshToken = $Refreshtoken
Add-AzDataTableEntity @Table -Entity $Secret -Force
} else {
Write-LogMessage -message 'Could not update refresh token. Will try again in 7 days.' -sev 'CRITICAL'
}
} else {
if ($env:MSI_SECRET) {
Disable-AzContextAutosave -Scope Process | Out-Null
$AzSession = Connect-AzAccount -Identity
}
$KV = $ENV:WEBSITE_DEPLOYMENT_ID
if ($Refreshtoken) {
Set-AzKeyVaultSecret -VaultName $kv -Name 'RefreshToken' -SecretValue (ConvertTo-SecureString -String $Refreshtoken -AsPlainText -Force)
if ($env:AzureWebJobsStorage -eq 'UseDevelopmentStorage=true') {
$Table = Get-CIPPTable -tablename 'DevSecrets'
$Secret = Get-CIPPAzDataTableEntity @Table -Filter "PartitionKey eq 'Secret' and RowKey eq 'Secret'"
if ($Secret) {
$Secret.RefreshToken = $Refreshtoken
Add-AzDataTableEntity @Table -Entity $Secret -Force
} else {
Write-LogMessage -API 'Update Tokens' -message 'Could not update refresh token. Will try again in 7 days.' -sev 'CRITICAL'
}
} else {
Write-LogMessage -message 'Could not update refresh token. Will try again in 7 days.' -sev 'CRITICAL'
if ($env:MSI_SECRET) {
Disable-AzContextAutosave -Scope Process | Out-Null
$AzSession = Connect-AzAccount -Identity
}
$KV = ($ENV:WEBSITE_DEPLOYMENT_ID -split '-')[0]
if ($Refreshtoken) {
Set-AzKeyVaultSecret -VaultName $KV -Name 'RefreshToken' -SecretValue (ConvertTo-SecureString -String $Refreshtoken -AsPlainText -Force)
} else {
Write-LogMessage -API 'Update Tokens' -message 'Could not update refresh token. Will try again in 7 days.' -sev 'CRITICAL'
}
}
} catch {
Write-LogMessage -API 'Update Tokens' -message 'Error updating refresh token, see Log Data for details. Will try again in 7 days.' -sev 'CRITICAL' -LogData (Get-CippException -Exception $_)
}

# Write an information log with the current time.
Write-Information "PowerShell timer trigger function ran! TIME: $currentUTCtime"

}
}

0 comments on commit 391da0d

Please sign in to comment.