[英]npm install behind one proxy but got Http Error=407 (Forefront TMG requires authorization)
My notebook uses MacOS, and already set up http(s) proxy inside the Network Preferences , but always failed to install any packages when running npm install
in the terminal, it popped up the error 407 Proxy Authentication Required
. 我的笔记本电脑使用MacOS,并且已经在网络偏好设置中设置了http(s)代理,但是在终端上运行
npm install
时始终无法安装任何软件包,它弹出了407 Proxy Authentication Required
错误。
So I installed the cntlm and applied the correct configuration. 因此,我安装了cntlm并应用了正确的配置。
Below is the test and it seems pass (return HTTP Code 200): 以下是测试,并且似乎通过了测试(返回HTTP代码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: 当我运行
npm i vue-cli -g
, cntlm确实收到了以下请求:
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: 但是nodejs抛出了以下异常:
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? 这让我感到困惑:因为测试是通过的,但是为什么cntlm仍然无法连接到npmjs.org?
Finally find out the solution : 最后找出解决方案 :
don't use plain text password ( add one #
at the beginning of the Password
line, like change Password XXX
to #Password XXX
) 不要使用纯文本密码 (在“
Password
行的开头添加一个#
,例如将“ Password XXX
更改为“ #
Password XXX
#Password XXX
)
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). 请改用PassLM , PassNT , PassNTLMv2 (似乎哈希值将再次阻止身份验证握手机制,这意味着您代表使用Windows用户帐户登录的应用程序)。
The default cntlm configuration file already introduces the steps how to generate them. 默认的cntlm配置文件已经介绍了如何生成它们的步骤。
My steps are as below: 我的步骤如下:
execute cntlm -H -d your_domain -u your_username
执行
cntlm -H -d your_domain -u your_username
then it prompts password, fill in your password then hit Enter : 然后提示输入密码, 输入密码,然后按Enter :
The output will be like below: 输出将如下所示:
Password:
PassLM F5314AF8A2DB16BDB7EE9FA6CFC5BC9A
PassNT 4EC02E0D65F8F0C1A9386C69CB6A2555
PassNTLMv2 28B089518C6573274C6B9D83D0EB8651
paste above hash values to the relevant fields in the configuration file. 将上面的哈希值粘贴到配置文件中的相关字段。
save then restart cntlm , it works. 保存然后重新启动cntlm ,它可以工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.