janhommes / o.js

o.js - client side oData lib.
https://janhommes.github.io/o.js/example/
MIT License
238 stars 57 forks source link

HTTPS mutual certificate example #154

Closed DJDaveMark closed 12 months ago

DJDaveMark commented 1 year ago

Do you have any examples of using HTTPS while supplying certificates?

I found an example using the https node module, but I'd like to use o.js to avoid crafting the odata URLs manually.

const https = require("https");
const fs = require("fs");

const requestParams = {
    hostname: "<the hostname>",
    port: 44300,
    key: fs.readFileSync("path/to/client-key.pem"),
    cert: fs.readFileSync("path/to/client-crt.pem"),
    ca: fs.readFileSync("path/to/ca-crt.pem"),
    rejectUnauthorized : false,
    path: "<the OData URL>",
    method: "<GET/POST/DELETE etc>"
};

const httpsReq = https.request(requestParams, httpsRes => {
    // Handle the response here
});

httpsReq.end();
DJDaveMark commented 1 year ago

I got an answer over on Stack Overflow: https://stackoverflow.com/a/75745957/344029