npm install behind one proxy 但得到 Http Error=407(Forefront TMG 需要授权)
npm install behind one proxy but got Http Error=407 (Forefront TMG requires authorization)
我的笔记本使用 MacOS,并且已经在 网络偏好设置 中设置了 http(s) 代理,但是 运行 [=13] 时总是无法安装任何包=] 在终端中,弹出错误 407 Proxy Authentication Required
.
所以我安装了 cntlm 并应用了正确的配置。
下面是测试,似乎通过 (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
当我运行 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
但是 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
让我很困惑:因为测试是通过的,但是为什么cntlm仍然无法连接到npmjs.org?
终于找到解决方法:
不要使用纯文本密码(在Password
行的开头添加一个#
,如更改Password XXX
到 #Password XXX
)
使用PassLM、PassNT、PassNTLMv2代替(看起来哈希值将再次阻止身份验证握手机制,这应该意味着您代表已登录 Windows 用户帐户的应用程序。
默认的cntlm配置文件已经介绍了生成的步骤
我的步骤如下:
执行cntlm -H -d your_domain -u your_username
然后提示输入密码,填写你的密码然后按Enter:
输出将如下所示:
Password:
PassLM F5314AF8A2DB16BDB7EE9FA6CFC5BC9A
PassNT 4EC02E0D65F8F0C1A9386C69CB6A2555
PassNTLMv2 28B089518C6573274C6B9D83D0EB8651
将以上哈希值粘贴到配置文件中的相关字段。
保存然后重启cntlm,成功了
我的笔记本使用 MacOS,并且已经在 网络偏好设置 中设置了 http(s) 代理,但是 运行 [=13] 时总是无法安装任何包=] 在终端中,弹出错误 407 Proxy Authentication Required
.
所以我安装了 cntlm 并应用了正确的配置。
下面是测试,似乎通过 (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
当我运行 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
但是 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
让我很困惑:因为测试是通过的,但是为什么cntlm仍然无法连接到npmjs.org?
终于找到解决方法:
不要使用纯文本密码(在
Password
行的开头添加一个#
,如更改Password XXX
到#Password XXX
)使用PassLM、PassNT、PassNTLMv2代替(看起来哈希值将再次阻止身份验证握手机制,这应该意味着您代表已登录 Windows 用户帐户的应用程序。
默认的cntlm配置文件已经介绍了生成的步骤
我的步骤如下:
执行
cntlm -H -d your_domain -u your_username
然后提示输入密码,填写你的密码然后按Enter:
输出将如下所示:
Password:
PassLM F5314AF8A2DB16BDB7EE9FA6CFC5BC9A
PassNT 4EC02E0D65F8F0C1A9386C69CB6A2555
PassNTLMv2 28B089518C6573274C6B9D83D0EB8651
将以上哈希值粘贴到配置文件中的相关字段。
保存然后重启cntlm,成功了