I have a React application being served by an express
web server. Within this app, I need to request a client certificate from a user when they click a "Login" button. This is for authorization using Common Access Cards.
My express
server uses the https
module with options set to require a client certificate. It prompts the user immediately when visiting the website, but I expected the prompt to only show when visiting/requesting the endpoint /authorize
because of this code:
# Serve React app
app.use(express.static(path.join(__dirname, "..", "build")));
# Request client certificate
app.get('/authenticate', (req, res) => {
const cert = req.connection.getPeerCertificate()
...
});
https.createServer(opts, app).listen(9999)
My "Login" button queries the /authorize
endpoint which returns the certificate's information as JSON.
How can I architect this application to maintain current functionality, but only prompt for client certificate after clicking the login button?