用 https模块请求restful api遇到认证库不通过的问题
发布于 9 年前 作者 ChopperLee2011 9156 次浏览 最后一次编辑是 8 年前 来自 问答

连接参数代码:

var options = { host: ‘em1.localdomain’, port: 7799, path: ‘/em/cloud’, method: ‘GET’, rejectUnauthorized: false, headers: { ‘Authorization’ : ‘basic U1NBX1VTRVIxOldlbGNvbWUx’, ‘Accept’: ‘application/oracle.com.cloud.common.Cloud+json’ }

如果options不加rejectUnauthorized: false, 会提示:

ERROR SELF_SIGNED_CERT_IN_CHAIN

如果加了会提示:

Some issues detected while trying to authenticate the user ‘USER1’. This may be intermittent" .Failed to login using repository authentication for user: USER1"

谁知道怎么解决吗?

2 回复

如果options不加rejectUnauthorized: false, 会提示 ERROR SELF_SIGNED_CERT_IN_CHAIN

估计你们使用了自签名证书. rejectUnauthorized缺省为true, 即如果服务器端证书通不过验证, 则不使用服务器提供的服务了, 同时会给出SELF_SIGNED_CERT_IN_CHAIN错误. 官网的解释如下: rejectUnauthorized: If true, the server certificate is verified against the list of supplied CAs. An ‘error’ event is emitted if verification fails. Verification happens at the connection level, before the HTTP request is sent. Default true.

如果加了会提示: Some issues detected while trying to authenticate the user 'USER1’. This may be intermittent" .Failed to login using repository authentication for user: USER1"

这表示你的认证信息(‘Authorization’ : 'basic U1NBX1VTRVIxOldlbGNvbWUx’)服务器已经接受了, 应该是服务器在处理认证的过程中出了错, 这个你需要和负责服务器Basic认证的人联系. 同时建议把认证信息中的basic改为Basic, 有些服务器比较挑剔. 另一个表明服务器接受了认证信息的证据是: 你的认证信息base64deconde之后为 SSAUSER1:Welcome1, 看起来你们的服务端还截取了SSA前缀部分, 从而给出了只包含了’USER1’的错误信息.

@GuoZhang 多谢你的详细解释,因为服务器端不可见,我只能在自己这边测试。 我用curl尝试发现用-k 参数后就可以返回200,但是还没有找到https模块里有insecure的开关。

回到顶部