Pipelines/Steps/Install/OnPrem/Sitecore/IdentityServer/9.1/Install-IdentityServer.ps1

$ErrorActionPreference = "Stop"

Write-Output "Install Identity Server started..."

$prefix = $SAFConfiguration.prefix
$license = $SAFConfiguration.license
$siteName = $SAFConfiguration.identityServer.hostName
$installDir = $SAFConfiguration.identityServer.installDir
$clientSecret = $SAFConfiguration.identityServer.clientSecret

$sqlServer = $SAFConfiguration.sql.serverName
$sqlSitecorePassword = $SAFConfiguration.sql.sitecorePassword
$sifConfiguration = GetSIFConfiguration -Name "IdentityServer.json" -ContextPath "$PSScriptRoot"
$package = Get-ChildItem -Path "$SAFInstallPackageDir\*" -Include *identityserver.scwdp.zip*
$serverCert = BuildSitecoreServerCertName -Prefix $prefix

$allowedCorsOrigins = ""
if ($SAFConfiguration.system.serverRole -eq "AllInOneQuickly") {
    foreach ($hostName in $SAFConfiguration.sitecore.hostNames) {
        $allowedCorsOrigins += "http://$hostName|https://$hostName|"
    }
}
else {
    foreach ($hostName in $SAFConfiguration.identityServer.allowedCorsOrigins) {
        $allowedCorsOrigins += "http://$hostName|https://$hostName|"
    }
}
$allowedCorsOrigins = $allowedCorsOrigins.TrimEnd('|')

$passwordRecoveryUrl = ""
if ($SAFConfiguration.system.serverRole -eq "AllInOneQuickly") {
    $passwordRecoveryUrl = "https://$($SAFConfiguration.sitecore.hostNames[0])"
}
else {
    $passwordRecoveryUrl = "https://$($SAFConfiguration.identityServer.passwordRecoveryHostName)" 
}

$identityServerParams = @{
    Path                 = $sifConfiguration
    Package              = $package.FullName
    SqlDbPrefix          = $prefix
    SitecoreIdentityCert = $serverCert
    LicenseFile          = $license
    Sitename             = $siteName
    SqlCoreUser          = "$($prefix)_coreuser"
    SqlCorePassword      = $sqlSitecorePassword
    SqlServer            = $sqlServer
    PasswordRecoveryUrl  = $passwordRecoveryUrl
    AllowedCorsOrigins   = $allowedCorsOrigins
    ClientSecret         = $clientSecret
    InstallDirectory     = $installDir
}
Install-SitecoreConfiguration @identityServerParams

Write-Output "Install Identity Server done."