Kri*_*son 5 client-certificates fetch node.js hashicorp-vault
我想存储客户端 PEM / KEY (PFX) 以供以后使用。我希望将其证书上传到我的服务器的用户是唯一可以在登录时访问它的用户。
然后使用证书来呼叫支付提供商。服务器只能上传一个新的证书,并添加一个“角色”,即登录用户是唯一可以访问的角色。服务器还可以删除证书。
尝试了 Azure Key Vault 和 Hashicorp Vault,但没有成功,可能是因为我还没有找到完成这项工作所需的信息
这是我当前的工作代码,但需要添加对登录用户证书和密钥的支持。
const payment = bodyData => {
return new Promise((resolve, reject) => {
fetch("https://mss.cpc.getswish.net/swish-cpcapi/api/v1/paymentrequests", {
agent: new https.Agent({
ca: fs.readFileSync(path.join(__dirname, "cert/Swish_TLS_RootCA.pem")),
// pfx: fs.readFileSync(path.join(__dirname, "cert/no.pfx")),
cert: fs.readFileSync(
path.join(
__dirname,
"cert/Swish_Merchant_TestCertificate_1231181189.pem"
)
),
key: fs.readFileSync(
path.join(
__dirname,
"cert/Swish_Merchant_TestCertificate_1231181189.key"
)
),
passphrase: "swish"
}),
method: "POST",
body: JSON.stringify(bodyData),
headers: { "Content-Type": "application/json" }
})
.then(res => {
if (res.status === 201) {
const location = res.headers.get("location");
if (location !== null) {
resolve(location.split("/").slice(-1)[0]);
} else {
reject(new Error("Unable to find 'location' parmas in header!"));
}
} else {
return res.json()
}
}).then(reject)
.catch(reject);
});
};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1149 次 |
| 最近记录: |