node.js - 在 NodeJS 中使用证书和 RSA 密钥获取令牌时出错
问题描述
我正在尝试使用密钥、证书和客户端 ID 在 NodeJS 中获取 oauth 令牌。
相同的代码:
var form = {
client_id : CLIENT_ID,
grant_type: 'client_credentials',
}
var headers= {
'content-type': 'application/x-www-form-urlencoded',
}
var option = {
method: 'POST',
url: CERTIFICATE_URL + "/oauth/token",
headers,
form,
httpsAgent:new https.Agent({
cert: CLIENT_CERTIFICATE.replace(/\\n/g, '\n'),
key: CLIENT_CERTIFICATE_KEY.replace(/\\n/g, '\n')
})
};
request(option, function(error, response, body) {
var token = null;
console.log(error);
console.log(JSON.parse(body).access_token)
if(!error && response.statusCode == 200) {
token = JSON.parse(body).access_token;
} else {
console.log(error)
error = error | new Error(body);
}
cb(error, token);
});
但出现以下错误:错误:写入 EPROTO 140062523283264:错误:14094410:SSL 例程:ssl3_read_bytes:sslv3 警报握手失败:../deps/openssl/openssl/ssl/record/rec_layer_s3.c:1544:SSL 警报号 40 2021 -10-13T23:46:56.23+0530 [APP/PROC/WEB/0] 在 WriteWrap.afterWrite [as oncomplete] (net.js:789:14) 输出错误:'EPROTO',代码:'EPROTO',系统调用: '写'
证书和密钥是从云环境本身生成和获取的。这是基于 x509 MTLS 的身份验证。
解决方案
能够使用 axios 库来做到这一点,请求库似乎已被弃用。
推荐阅读
- typescript - 无法将属性添加到 passport-linkedin-oauth2 声明文件的接口
- php - json、ajax 和 php 将转换后的 json 打印为字符串时出错
- r - 在 r 中使用嵌套函数处理变量
- amazon-web-services - 如何在没有用户密码的情况下获取用户的 idToken?AWS-认知
- php - 拒绝数组中的某些索引参数
- ruby - 文本输出为多个单独的行,而不是一个带有换行符的段落
- python - Python; jsonschema,验证模式是否有效 jsonschema
- sql-server - SQL Server 中的矩阵输出类型
- python - 字符串比较同时包含数字和字母时如何工作?
- c++ - 使用 WinApi 获取与“高级显示设置”面板中相同的显示名称