Ste*_*veC 20 proxy visual-studio-code
如何使用身份验证代理指定Visual Studio代码的用户标识和密码?
我在主要的VS Code网站上看到了代理服务器支持,但这只提到了两个设置......
"http.proxy": "http://10.203.0.1:5187/"
"http.proxyStrictSSL": false
Run Code Online (Sandbox Code Playgroud)
我已经设置了这些,但仍然没有运气,例如我无法安装扩展程序......甚至无法获取它们的列表
我怀疑它是我们的代理,因为它需要用户ID和密码:-(
那你怎么设置这些值呢?
Osc*_*car 27
在代理URL中设置凭据:
http://username:password@10.203.0.1:5187/
Run Code Online (Sandbox Code Playgroud)
Dav*_*tin 23
如果您不想将凭据存储在设置文件中,可以使用fiddler代理对代理的调用.此外,我相信上述仅适用于使用基本身份验证的代理服务器,以下内容适用于NTLM.
VSCode打开设置文件:
%APPDATA%\代码\用户\ settings.json
添加以下内容:
{
"http.proxy": "http://127.0.0.1:8888",
"http.proxyStrictSSL": false
}
Run Code Online (Sandbox Code Playgroud)
提琴手确认提琴手设置:
Fiddler确保Fiddler设置为自动验证:
VSCode Extensions现在应该在线:
更新
现在,在版本1.15 代理服务器身份验证中实现PR#22369后,现在不再需要这样做了.
在我的情况下,我仍然需要添加:
"http.proxyStrictSSL": false
Run Code Online (Sandbox Code Playgroud)
我最喜欢的回应是David Martin建议使用Fiddler.但是,如果您不想进行此操作,则下面是如何设置代理的凭据.
要指定DOMAIN +用户名+密码:(它可能无法使用斜杠,因此请使用%5C代替斜杠,如下所示)
// The proxy setting to use. If not set will be taken from the http_proxy and https_proxy environment variables
"http.proxy": "http://DOMAIN%5Cusername:password@proxy_name_or_ip:port",
"https.proxy": "http://DOMAIN%5Cusername:password@proxy_name_or_ip:port",
// Whether the proxy server certificate should be verified against the list of supplied CAs.
"http.proxyStrictSSL": false,
Run Code Online (Sandbox Code Playgroud)
仅指定用户名+密码:
// The proxy setting to use. If not set will be taken from the http_proxy and https_proxy environment variables
"http.proxy": "http://username:password@proxy_name_or_ip:port",
"https.proxy": "http://username:password@proxy_name_or_ip:port",
// Whether the proxy server certificate should be verified against the list of supplied CAs.
"http.proxyStrictSSL": false,
Run Code Online (Sandbox Code Playgroud)
尊敬的 CNTLM 可以帮助您。你给它你的凭据,告诉它上游代理,在你的本地机器上运行它,然后将 VS 指向http://localhost:3128的代理。
对于任何不支持经过身份验证的代理的应用程序来说,这是一个方便的解决方案。
我真的很喜欢 David Martin 使用 Fiddler 发布的解决方案(如下),但是我想弄清楚如何使用http.proxyAuthorization,这是我的解决方案,考虑到您可以将凭据以 Base64 编码格式保存在文件中settings.json。
警告:以 Base64 编码格式保存凭据当然比纯文本更好,但是请将 Base64 编码视为混淆而不是加密,并且帐户仍然可能受到威胁 - 使用时请自行承担风险。考虑修改设置文件的 ACL 以减少对其的读取访问。
第 1 步:使用以下代码对您的凭据进行编码:
var s = @"DOMAIN\user:pass";
var bytes = System.Text.Encoding.UTF8.GetBytes(s);
Console.WriteLine(Convert.ToBase64String(bytes));
Run Code Online (Sandbox Code Playgroud)
RE9NQUlOXHVzZXI6cGFzcw==
步骤 2http.proxyAuthorization :通过添加使用上面的 base64 编码值来更新 VS Code 设置:
{
"https.proxy": "https://internal-proxy.corp.net:8080",
"http.proxyAuthorization": "Authorization: Basic RE9NQUlOXHVzZXI6cGFzcw=="
}
Run Code Online (Sandbox Code Playgroud)
第 3 步settings.json:通过更新 ACL 来确保安全
由于您已在文件中存储凭据以提高安全性,因此您可以通过删除本地管理员组来修改设置文件的 ACL - 确保只有您可以读取此文件。例如,我使用以下 PowerShell 脚本删除本地管理员组:
#Requires -Version 5.1
# PowerShell 5.1 min version required for the code below
$settings = "$env:appdata\Code\$env:username\settings.json"
$acl = (Get-Item $settings).GetAccessControl('Access')
$acl.SetAccessRuleProtection($true,$true) # removes the ACL inheritance
$accesToRemove = $acl.Access | ?{ $_.IsInherited -eq $false -and $_.IdentityReference -eq 'BUILTIN\Administrators' }
$acl.RemoveAccessRule($accesToRemove)
Set-Acl -AclObject $acl $settings
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
41464 次 |
| 最近记录: |