如何使用nodejs多次签署SOAP请求

问题描述 投票:0回答:1

我是 SOAP 新手,我需要在这里使用它。

我正在尝试向外部端点发送 SOAP 请求。
为了让它工作,我必须使用证书多次签署 SOAP 请求并对其进行加密。
我使用 WSSecurityCert 函数尝试了 node-soap 包,为其提供私钥、公钥和密码,但这只能让我签名一次。
使用函数setSecurity两次并没有添加两个签名。

我的理解是,soap 包允许您配置所有内容,但最终只创建 XML。这意味着我只能在发送后查看创建的 XML。

我的问题是:

  • 有没有办法只对 XML 进行签名并将其取回,然后再次对其进行签名并最终加密所有内容?手动执行该过程。
  • 还有其他活动包或方法可以使用 Nodejs 实现此目的吗?
javascript node.js typescript soap xml-signature
1个回答
0
投票

尝试这样做

const soap = require('soap');
const crypto = require('crypto');

// SOAP request payload
const soapRequest = {
  // Your SOAP request content
};

function signSoapEnvelope(soapEnvelope) {
  // Your signing logic here
  const timestamp = new Date().toISOString();
  soapEnvelope.Header = {
    Timestamp: timestamp,
    // Other headers...
  };

  // You may also want to sign the SOAP body or other parts as needed
  // ...

  return soapEnvelope;
}

soap.createClient(url, (err, client) => {
  if (err) {
    console.error(err);
    return;
  }
  let signedSoapRequest = signSoapEnvelope(soapRequest);
  signedSoapRequest = signSoapEnvelope(signedSoapRequest); // you could sign it here again
  client.MySoapOperation(signedSoapRequest, (err, result) => {
    if (err) {
      console.error(err);
      return;
    } 
    console.log(result);
  });
});
© www.soinside.com 2019 - 2024. All rights reserved.