大网数据广告活动
服务器运维问答

npm install behind one proxy but got Http Error=407 (Forefront TMG requires authorization)

· 52CE 我爱测

The operating system is MacOS, and already set up http(s) proxy inside the Network Preferences , but always failed to install any packages when running npm install (npm is one package installer for nodejs) in the terminal, it pop…

问题原文

原帖链接 · Sphinx · CC BY-SA 4.0

The operating system is MacOS, and already set up http(s) proxy inside the Network Preferences, but always failed to install any packages when running npm install (npm is one package installer for nodejs) in the terminal, it popped up the error 407 Proxy Authentication Required.

So I installed the cntlm and applied the correct configuration.

Below is the test and it seems pass (return HTTP Code 200):

cntlm -c /usr/local/etc/cntlm.conf -I -M http://registry.npmjs.org/vue
Password: 
Config profile  1/4... OK (HTTP code: 200)
----------------------------[ Profile  0 ]------
Auth            NTLMv2
PassNTLMv2      28B089518C6573274C6B9D83D0XXXXXX

When I ran npm i vue-cli -g, cntlm did receive the request as below:

cntlm -c /usr/local/etc/cntlm.conf -f
Oct 15 15:12:29  cntlm[17646] <Info>: Cntlm ready, staying in the foreground
Oct 15 15:12:38  cntlm[17646] <Info>: Using proxy company-proxy:80
Oct 15 15:12:38  cntlm[17646] <Debug>: 127.0.0.1 GET http://registry.npmjs.org/nexe

But nodejs threw out below exceptions:

npm i vue-cli -g
npm ERR! code E407
npm ERR! 407 Proxy Authentication Required ( Forefront TMG requires authorization to fulfill the request. Access to the Web Proxy filter is denied.  ): vue-cli@latest

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/****/.npm/_logs/2018-10-15T23_13_47_019Z-debug.log

It confused me: because the test is PASS, but why the cntlm still failed to connect to npmjs.org?

已采纳解答

原帖链接 · Sphinx · CC BY-SA 4.0

Finally find out the solution:

  1. don't use plain text password ( add one # at the beginning of the Password line, like change Password XXX to #Password XXX)

  2. use PassLM, PassNT, PassNTLMv2 instead (it seems hash values will prevent from auth handshake mechanism again, which should mean you are on behalf of the applications with logged in Windows user account).

The default cntlm configuration file already introduces the steps how to generate them.

My steps are as below:

  1. execute cntlm -H -d your_domain -u your_username

  2. then it prompts password, fill in your password then hit Enter:

The output will be like below:

Password:
PassLM          F5314AF8A2DB16BDB7EE9FA6CFC5BC9A
PassNT          4EC02E0D65F8F0C1A9386C69CB6A2555
PassNTLMv2      28B089518C6573274C6B9D83D0EB8651 
  1. paste above hash values to the relevant fields in the configuration file.

  2. save then restart cntlm, it works.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2018-10-17)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。