Skip to content

Commit

Permalink
Merge pull request oktadev#245 from AlainODea/ao-BUG-socks-proxy-windows
Browse files Browse the repository at this point in the history
🐛 SOCKS proxy won't work on Windows
  • Loading branch information
AlainODea authored Nov 20, 2018
2 parents a95b8a4 + 6aa27c9 commit 9a9ca5c
Showing 1 changed file with 30 additions and 8 deletions.
38 changes: 30 additions & 8 deletions bin/Install-OktaAwsCli.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,42 @@ OKTA_BROWSER_AUTH=true
#OktaAWSCLI
function With-Okta {
Param([string]$Profile)
Write-Host $args
$OriginalOKTA_PROFILE = $env:OKTA_PROFILE
try {
$env:OKTA_PROFILE = $Profile
$InternetOptions = Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings"
if ($InternetOptions.ProxyServer) {
($ProxyHost, $ProxyPort) = $InternetOptions.ProxyServer.Split(":")
}
if ($InternetOptions.ProxyOverride) {
$NonProxyHosts = [System.String]::Join("|", ($InternetOptions.ProxyOverride.Replace("<local>", "").Split(";") | Where-Object {$_}))
if ($InternetOptions.ProxyEnable) {
$ProxyStrings = $InternetOptions.ProxyServer.Split(";")
$Proxies = @{}
ForEach ($ProxyString in $ProxyStrings) {
if ($ProxyString.Contains("=")) {
($ProxyProtocol,$ProxyServerPort) = $ProxyString.Split("=")
} else {
($ProxyProtocol,$ProxyServerPort) = ("http", $ProxyString)
}
($ProxyHost, $ProxyPort) = $ProxyServerPort.Split(":")
$Proxies[$ProxyProtocol] = ($ProxyHost, $ProxyPort)
}
if ($Proxies.socks) {
($ProxyHost, $ProxyPort) = $Proxies.socks
} elseif ($Proxies.https) {
($ProxyHost, $ProxyPort) = $Proxies.https
} elseif ($Proxies.http) {
($ProxyHost, $ProxyPort) = $Proxies.http
}
if ($InternetOptions.ProxyOverride) {
$NonProxyHosts = [System.String]::Join("|", ($InternetOptions.ProxyOverride.Replace("<local>", "").Split(";") | Where-Object {$_}))
} else {
$NonProxyHosts = ""
}
if ($ProxyProtocol -eq "socks") {
java "-DsocksProxyHost=$ProxyHost" "-DsocksProxyPort=$ProxyPort" "-Dhttp.nonProxyHosts=$NonProxyHosts" -classpath $HOME\.okta\* com.okta.tools.WithOkta @args
} else {
java "-Dhttp.proxyHost=$ProxyHost" "-Dhttp.proxyPort=$ProxyPort" "-Dhttps.proxyHost=$ProxyHost" "-Dhttps.proxyPort=$ProxyPort" "-Dhttp.nonProxyHosts=$NonProxyHosts" -classpath $HOME\.okta\* com.okta.tools.WithOkta @args
}
} else {
$NonProxyHosts = ""
java -classpath $HOME\.okta\* com.okta.tools.WithOkta @args
}
java "-Dhttp.proxyHost=$ProxyHost" "-Dhttp.proxyPort=$ProxyPort" "-Dhttps.proxyHost=$ProxyHost" "-Dhttps.proxyPort=$ProxyPort" "-Dhttp.nonProxyHosts=$NonProxyHosts" -classpath $HOME\.okta\* com.okta.tools.WithOkta @args
} finally {
$env:OKTA_PROFILE = $OriginalOKTA_PROFILE
}
Expand Down

0 comments on commit 9a9ca5c

Please sign in to comment.