Skip to content

Instantly share code, notes, and snippets.

@magician11
Last active December 4, 2018 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save magician11/0b07075eafcf49e1677f354ed3492571 to your computer and use it in GitHub Desktop.
Save magician11/0b07075eafcf49e1677f354ed3492571 to your computer and use it in GitHub Desktop.
How to a JSON API Wrapper for SOAP
const express = require('express');
const https = require('https');
const fs = require('fs');
const cors = require('cors');
const rpn = require('request-promise-native');
const bodyParser = require('body-parser');
/* eslint-disable comma-dangle,arrow-parens,max-len,no-console */
const app = express();
app.use(cors());
app.set('port', 2323);
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.post('/check-age', (req, res) => {
const {
firstName,
lastName,
year,
month,
day,
minAge,
stateCode,
zip
} = req.body;
const xmlReqBody = `
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.identityproofing.idm.risk.someurl.com/" xmlns:ns="http://ns.someurl.com/identity-proofing/1.0" xmlns:ns1="http://ns.someurl.com/survey/1.0">
<soapenv:Header>
<wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken wsu:Id="UsernameToken-49" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:Username>someUserName</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">somePassword</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
<ws:invokeIdentityService>
<identityProofingRequest ns:customerReference="TESTING" ns:locale="en_US" ns:transactionID="${new Date().toString()}" ns:version="2" xmlns="http://ns.someurl.com/identity-proofing/1.0" xmlns:ns2="http://ns.someurl.com/identity-proofing/1.0">
<ns:workFlow>WorkFlow</ns:workFlow>
<ns:inputSubject>
<ns:person>
<ns:name>
<ns:first>${firstName}</ns:first>
<ns:last>${lastName}</ns:last>
</ns:name>
<ns:dateOfBirth>
<ns:Year>${year}</ns:Year>
<ns:Month>${month}</ns:Month>
<ns:Day>${day}</ns:Day>
</ns:dateOfBirth>
<ns:address ns:addressPurpose="PRIMARY_RESIDENCE">
<ns:stateCode>${stateCode}</ns:stateCode>
<ns:zip5>${zip}</ns:zip5>
</ns:address>
</ns:person>
</ns:inputSubject>
</identityProofingRequest>
</ws:invokeIdentityService>
</soapenv:Body>
</soapenv:Envelope>`;
const options = {
method: 'POST',
uri: 'https://identitymanagement.someurl.com/identity-proofing/services/identityProofingServiceWS/v2',
body: xmlReqBody
};
rpn(options)
.then(response => {
// do something with the response, then return it
res.json(response);
})
.catch(err => {
console.log(err);
});
});
// Make sure the connection to the node server is encrypted
const sslOptions = {
key: fs.readFileSync('/etc/letsencrypt/live/nodesrvr.com/privkey.pem'),
cert: fs.readFileSync('/etc/letsencrypt/live/nodesrvr.com/fullchain.pem'),
ca: fs.readFileSync('/etc/letsencrypt/live/nodesrvr.com/chain.pem')
};
// startup the https server
https.createServer(sslOptions, app).listen(app.get('port'), () => {
console.log(`Age checker listening on port ${app.get('port')}.`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment