Skip to content

Commit ceb53fa

Browse files
authored
Add error handling during the creation of Entra ID App Registration (#255)
* error handling on client_secret * fix typo
1 parent f8af48d commit ceb53fa

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

infra/scripts/postprovision/create-app-registrations.ps1

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -461,12 +461,19 @@ if ($clientSecrets) {
461461
}
462462

463463
# Create a new client secret with a 1 year expiration
464-
$clientSecrets = New-AzADAppCredential -ObjectId $frontendAppRegistration.Id -EndDate (Get-Date).AddYears(1) -ErrorAction Stop
464+
try {
465465

466-
# Write to Key Vault
467-
$secretValue = ConvertTo-SecureString -String $clientSecrets.SecretText -AsPlainText -Force
468-
Set-AzKeyVaultSecret -VaultName $keyVault.VaultName -Name 'MicrosoftEntraId--ClientSecret' -SecretValue $secretValue -ErrorAction Stop > $null
469-
Write-Host "`tSaved the $highlightColor'MicrosoftEntraId--ClientSecret'$defaultColor to Key Vault"
466+
$clientSecrets = New-AzADAppCredential -ObjectId $frontendAppRegistration.Id -EndDate (Get-Date).AddYears(1) -ErrorAction Stop
467+
468+
# Write to Key Vault
469+
$secretValue = ConvertTo-SecureString -String $clientSecrets.SecretText -AsPlainText -Force
470+
Set-AzKeyVaultSecret -VaultName $keyVault.VaultName -Name 'MicrosoftEntraId--ClientSecret' -SecretValue $secretValue -ErrorAction Stop > $null
471+
Write-Host "`tSaved the $highlightColor'MicrosoftEntraId--ClientSecret'$defaultColor to Key Vault"
472+
} catch {
473+
$errorMessage = $_.Exception.Message
474+
Write-Warning "An error occurred saving $highlightColor'MicrosoftEntraId--ClientSecret'$defaultColor to Key Vault: $errorMessage"
475+
Write-Warning "Please save the client secret manually or users will not be able to make authenticated requests to the web API during checkout."
476+
}
470477

471478
# Get or Create the api app registration
472479
$apiAppRegistration = Get-ApiAppRegistration `

0 commit comments

Comments
 (0)