Public/ps1/Html/Get-ApprxrAuthenticationRoute.ps1
|
function Get-ApprxrAuthenticationRoute { param( $hostURI, $channelId, $id, $type ) # Check if debug mode is enabled $debugMode = $false try { $debugConfig = Get-ApprxrConfigurationValue -name "ApprxrHtmlDebugMode" -ErrorAction SilentlyContinue if ($debugConfig -and ($debugConfig -eq $true -or $debugConfig -eq "true" -or $debugConfig -eq "1")) { $debugMode = $true } } catch { # Configuration value not found, continue without debug mode } if ($debugMode) { Log "[Get-ApprxrAuthenticationRoute] DEBUG: Starting with parameters - hostURI: $hostURI, channelId: $channelId, id: $id, type: $type" } else { Log "[Get-ApprxrAuthenticationRoute] INFO: Starting authentication route lookup" } $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 if ($debugMode) { Log "[Get-ApprxrAuthenticationRoute] DEBUG: Lookup by ID - Generated authenticationId: $authenticationId" } } elseif ($authenticationPath.hostUri -and $authenticationPath.type) { # Lookup by hosturi and type $authenticationId = Get-ApprxrAuthenticationId -channelId $authenticationPath.channelId -hostURI $authenticationPath.hostUri -type $authenticationPath.type if ($debugMode) { Log "[Get-ApprxrAuthenticationRoute] DEBUG: Lookup by hostUri and type - Generated authenticationId: $authenticationId" } } elseif ($authenticationPath.hostUri) { # Lookup by hosturi only $authenticationId = Get-ApprxrAuthenticationId -channelId $authenticationPath.channelId -hostURI $authenticationPath.hostUri if ($debugMode) { Log "[Get-ApprxrAuthenticationRoute] DEBUG: Lookup by hostUri only - Generated authenticationId: $authenticationId" } } if ($authenticationId) { $authenticationInformation = Get-ApprxrConfigurationValue -name $authenticationId -secure if ($debugMode) { Log "[Get-ApprxrAuthenticationRoute] DEBUG: Retrieved configuration for ID '$authenticationId' - Found: $($null -ne $authenticationInformation)" } } if ($authenticationInformation) { $authObj = $authenticationInformation | ConvertFrom-Json if ($debugMode) { Log "[Get-ApprxrAuthenticationRoute] DEBUG: Authentication type: $($authObj.type)" } if ($authObj.type -eq 'NTLM') { if ($debugMode) { Log "[Get-ApprxrAuthenticationRoute] DEBUG: Returning NTLM authentication with Negotiate scheme" } $returnObj = [PSCustomObject]@{ username = $authObj.username password = $authObj.password Authentication = "Negotiate" } return $returnObj } else { # Return authentication object for other types if ($debugMode) { Log "[Get-ApprxrAuthenticationRoute] DEBUG: Returning authentication object for type: $($authObj.type)" } return $authObj } } else { # No authentication found if ($debugMode) { Log "[Get-ApprxrAuthenticationRoute] DEBUG: No authentication information found" } return $null } } |