Public/ps1/Html/Get-AuthenticationRoute.ps1

function Set-AuthenticationRoute {
    param(
        $hostURI,
        $channelId,
        $id,
        $type
    )

    $authenticationPath = @{
        hostUri = $hostURI
        channelId = $channelId
        id = $id
        type = $type
    }


    # Determine the authentication id based on the provided parameters
    $authenticationId = $null
    $authenticationInformation = $null

    if ($authenticationPath.id) {
        # Lookup by id
        $authenticationId = Get-ApprxrAuthenticationId -channelId $authenticationPath.channelId -id $authenticationPath.id -hostURI $authenticationPath.hostUri -type $authenticationPath.type
    } elseif ($authenticationPath.hostUri -and $authenticationPath.type) {
        # Lookup by hosturi and type
        $authenticationId = Get-ApprxrAuthenticationId -channelId $authenticationPath.channelId -hostURI $authenticationPath.hostUri -type $authenticationPath.type
    } elseif ($authenticationPath.hostUri) {
        # Lookup by hosturi only
        $authenticationId = Get-ApprxrAuthenticationId -channelId $authenticationPath.channelId -hostURI $authenticationPath.hostUri
    }

    if ($authenticationId) {
        $authenticationInformation = Get-ConfigurationValue -name $authenticationId -secure
    }

    if ($authenticationInformation) {
        $authObj = $authenticationInformation | ConvertFrom-Json
        
        if ($authObj.type -eq 'NTLM') {
            $returnObj = [PSCustomObject]@{
                username = $authObj.username
                password = $authObj.password
                Authentication = "Negotiate"
            }
            return $returnObj
        } else {
            # Return authentication object for other types
            return $authObj
        }
    } else {
        # No authentication found
        return $null
    }
}