Skip to content

Commit

Permalink
error handling on client_secret
Browse files Browse the repository at this point in the history
  • Loading branch information
KSchlobohm authored Sep 12, 2024
1 parent 039fbe8 commit 146978d
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions infra/scripts/postprovision/create-app-registrations.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -461,12 +461,19 @@ if ($clientSecrets) {
}

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

# Write to Key Vault
$secretValue = ConvertTo-SecureString -String $clientSecrets.SecretText -AsPlainText -Force
Set-AzKeyVaultSecret -VaultName $keyVault.VaultName -Name 'MicrosoftEntraId--ClientSecret' -SecretValue $secretValue -ErrorAction Stop > $null
Write-Host "`tSaved the $highlightColor'MicrosoftEntraId--ClientSecret'$defaultColor to Key Vault"
$clientSecrets = New-AzADAppCredential -ObjectId $frontendAppRegistration.Id -EndDate (Get-Date).AddYears(1) -ErrorAction Stop

# Write to Key Vault
$secretValue = ConvertTo-SecureString -String $clientSecrets.SecretText -AsPlainText -Force
Set-AzKeyVaultSecret -VaultName $keyVault.VaultName -Name 'MicrosoftEntraId--ClientSecret' -SecretValue $secretValue -ErrorAction Stop > $null
Write-Host "`tSaved the $highlightColor'MicrosoftEntraId--ClientSecret'$defaultColor to Key Vault"
} catch {
$errorMessage = $_.Exception.Message
Write-Warning "An error occurred saving $highlightColor'MicrosoftEntraId--ClientSecret'$defaultColor to Key Vault: $errorMessage"
Write-WWarning "Please save the client secret manually or users will not be able to make authenticated requests to the web API during checkout."
}

# Get or Create the api app registration
$apiAppRegistration = Get-ApiAppRegistration `
Expand Down

0 comments on commit 146978d

Please sign in to comment.