Private/PartnerActions/Get-SAMTokens.ps1
function Get-SAMTokens() { # Start by connecting to our Azure Key Vault. $AzContext = Get-AzContext if (!$AzContext -or $AzContext.Tenant.Id -ne $PartnerTenantId) { try { Write-Host "Please log in to Azure with your @jlhosting.dk account. A browser window has been opened." -ForegroundColor Yellow Connect-AzAccount -Tenant $PartnerTenantId -SubscriptionName $SubscriptionName | Out-Null } catch { Write-Error "Failed to connect to Azure. Please make sure you have the Az module installed." } } try { # Retreive all required values from Azure Key Vault $ApplicationId = Get-AzKeyVaultSecret -VaultName $KeyVaultName -Name "ApplicationId" -AsPlainText $ApplicationSecret = Get-AzKeyVaultSecret -VaultName $KeyVaultName -Name "ApplicationSecret" -AsPlainText $RefreshToken = Get-AzKeyVaultSecret -VaultName $KeyVaultName -Name "RefreshToken" -AsPlainText $ExchangeRefreshToken = Get-AzKeyVaultSecret -VaultName $KeyVaultName -Name "ExchangeRefreshToken" -AsPlainText $Curanet3850APISecret = Get-AzKeyVaultSecret -VaultName $KeyVaultName -Name "curanet3850apisecret" -AsPlainText $ApplicationCredential = (New-Object System.Management.Automation.PSCredential ($ApplicationId, (ConvertTo-SecureString $ApplicationSecret -AsPlainText -Force))) } catch { Write-Error "Failed to connect to Azure Key Vault and retreive secrets." } return [PSCustomObject]@{ ApplicationId = $ApplicationId ApplicationSecret = $ApplicationSecret RefreshToken = $RefreshToken ExchangeRefreshToken = $ExchangeRefreshToken ApplicationCredential = $ApplicationCredential Curanet3850APISecret = $Curanet3850APISecret } } |