I am trying to use SSL authentication with Express as discussed in http://intown.biz/2016/11/22/node-client-auth/.
We are using TypeScript for our server code (in addition to client Angular code) for the strong typing benefit. We are using Express 4.14.1, @types/express": "^4.0.36"
The link above (as is the case with most server side NodeJS) is JavaScript not TypeScript. There is a chunk of code in the link that looks like the following:
app.use(function (req, res, next) {
if (!req.client.authorized) {
return res.status(401).send('User is not authorized');
}
#examine the cert itself, and even validate based on that!
var cert = req.socket.getPeerCertificate();
if (cert.subject) {
console.log(cert.subject.CN);
}
next();
});
The application discussed in the link works (he has a link to download the project).
My problem: The latest types (4.0.36) don’t seem to have req.client or req.socket.getPeerCertificate(). They are not available in my TypeScript code (we do have Express imported/required). Also, I tried passing the TypeScript Request object into a plain JavaScript function and req.client and req.socket.getPeerCertificate() are still undefined. They just aren't there.
Note: We do have Passport initialized also. We are using that to authenticate our web application (client and internal REST API) but we have an external/separate REST API that we wish to secure with SSL certificates. I doubt that having Passport plugged in would cause the the req.client and req.socket.getPeerCertificate() features to disappear?
Can anyone tell me why I am not seeing req.client or req.socket.getPeerCertificate() in my Express code? Did they get replaced with something?
Any help/ acknowledgements with this would be appreciated.