How to specify a user id and password for Visual Studio Code with an authenticating proxy?
I\'ve seen the Proxy Server Support on the main VS Code site, but this onl
If you don't want to store your credentials in the settings file, fiddler can be used to proxy the call to the proxy. Furthermore, I believe the above only works for proxy servers using basic authentication, the following should work for NTLM.
VSCode Open Settings File:
%APPDATA%\Code\User\settings.json
add the following:
{
"http.proxy": "http://127.0.0.1:8888",
"http.proxyStrictSSL": false
}
Fiddler Confirm fiddler settings:
Fiddler Ensure Fiddler set to automatically authenticate:
VSCode Extensions should now be online:
Update
This is now no longer required following implementation of PR #22369 which was implemented in version 1.15 Proxy server authentication.
In my case I still needed to add:
"http.proxyStrictSSL": false
Use the below command and replace the username,password and ip address of you proxy:port
PS C:\Users\rathakrishnan> npm config set proxy http://username:password@172.18.10.27:3128
PS C:\Users\rathakrishnan> npm install -g @angular/cli
Please take ref to this article. https://taeguk.co.uk/blog/working-in-visual-studio-behind-the-firewall/
Let’s assume my NTLM login is DOMAIN\User Name and my password is P@ssword! The format for the credentials needs to be DOMAIN\User Name:P@ssword!, but you need to URL Encode the user name and password. A simple online URL encoded can translate your username and password to: DOMAIN%5CUser%20Name and P%40ssword!. Piece all this info into a single string like so: http://DOMAIN%5CUser%20Name:P%40ssword!@proxy-cluster.fqdn.local:8881 Then add this into your User Settings in File, Preferences against the "http.proxy" value: // Place your settings in this file to overwrite the default settings { "http.proxy": "http://DOMAIN%5CUser%20Name:P%40ssword!@proxy-cluster.fqdn.local:8881" }
"http.proxy": "http://DOMAIN//USER:PASSWORD@wsg.test.com:8080". Do not forget to add the port.
in Visual Studio Code (my version is 1.32.3) you write a request, i.e.
### my request
GET https://defdomain.prefix.com/app/resource
Authorization: bXl1c2VyOnVzZXIyMkBwYXNzd29yZA==
Wherefore the Authorization header is of type "Basic base64encoded" and consists of myuser:user22@password (username:usercredentials) base64 encoded. Thats all.
I really like the solution David Martin posted (further below) using Fiddler, however I wanted to figure out how to use http.proxyAuthorization
and here is my solution considering you are OK to have credtials saved in base64 encoded format in the settings.json
file.
WARNING: Saving credentials in base64 encoded format is certainly better than plain text, however consider base64 encoding as obfuscation not an ecryption and the account can still be compromised - use at your own risk. Consider modifying the ACL of the settings file to reduce read acess to it.
Step 1: Encode your credentials using the code below:
var s = @"DOMAIN\user:pass";
var bytes = System.Text.Encoding.UTF8.GetBytes(s);
Console.WriteLine(Convert.ToBase64String(bytes));
RE9NQUlOXHVzZXI6cGFzcw==
Step 2: Update VS Code settings by adding http.proxyAuthorization
using the base64 encoded value from above:
{
"https.proxy": "https://internal-proxy.corp.net:8080",
"http.proxyAuthorization": "Authorization: Basic RE9NQUlOXHVzZXI6cGFzcw=="
}
Step 3: Secure the settings.json
by updating it's ACL
Since you have stored credentials in the file to increase the security you can modify the ACL of the settings file by removing the local administrators group - make sure only you can read this file. I used the following PowerShell script to remove the local admin group for example:
$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