Public/ps1/Configuration/Authentication/Set-ApprxrAuthenticationRoute.ps1

<#
    .SYNOPSIS
    Sets the authentication route configuration for a given host and channel.
 
    .DESCRIPTION
    This function creates and stores an authentication path object for a specific host URI, channel, and user credentials.
    The configuration is stored securely using Set-ApprxrConfigurationValue.
 
    .PARAMETER hostURI
    The URI of the host for authentication.
 
    .PARAMETER channelId
    The channel identifier for the authentication route.
 
    .PARAMETER id
    The unique identifier for the authentication route.
 
    .PARAMETER type
    The type of authentication or connection.
 
    .PARAMETER username
    The username for authentication.
 
    .PARAMETER password
    The password for authentication.
 
    .NOTES
    The parameter and hashtable assignment have been corrected to 'username'.
#>

function Set-ApprxrAuthenticationRoute {
    param(
        $hostURI,
        $channelId,
        $id,
        $type,
        $username,
        $password
    )
    # Build the authentication path object
    $authenticationInformation = @{
        hostUri = $hostURI
        channelId = $channelId
        id = $id
        type = $type
        username = $username
        password = $password
    }

    Log("Creating authentication route for HostURI: $hostURI, ChannelId: $channelId, ID: $id, Type: $type, Username: $username, Password: ********")
    Log("The object is $($authenticationInformation | ConvertTo-Json -Depth 10)")

    # Generate a unique authentication ID based on the path details
    $authenticationId = Get-ApprxrAuthenticationId -channelId ($authenticationInformation.channelId) -id ($authenticationInformation.id) -hostURI ($authenticationInformation.hostUri) -type ($authenticationInformation.type)
    
    Log("Storing authentication route with ID: $authenticationId")
    Write-host " The object: $($authenticationInformation | ConvertTo-Json -Depth 10)"
    
    # Store the authentication path securely in configuration
    Set-ApprxrConfigurationValue -name $authenticationId -value (ConvertTo-Json $authenticationInformation) -secure
}

function Log{
    param(
        [string]$message
    )
    Write-Host "[Set-ApprxrAuthenticationRoute] $message" -ForegroundColor DarkGray
}