Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node https.Agent in browser

Part of my npm module (typescript) is using axios to make web requests. One of the possible endpoints is using certificates for authentication. For this scenario I'm passing new https.Agent to axios to send the certificates info. All is working fine if the module is used from within Node app.

The problem is if I try and use my module in browser environment. When in browser https module do not exists and I'm unable to use my module.

  • Is there any way to use https module in the browser?
  • If not - can https be bundled within my module somehow? Do I have to use some bundler in this case (like Rollup) to build the typescript module?
like image 289
Stefan Stoichev Avatar asked Oct 23 '25 00:10

Stefan Stoichev


1 Answers

You can't do it. Most browsers support TLS Client Certificate authentication, but it works differently: the user is presented with a window and asked to select a certificate to authenticate with. It's a similar story to how cookies work - you can't easily manipulate HttpOnly cookies from JS on the client side.

If you want TLS client auth in the browser, you are at the browser vendor's mercy.

like image 147
Robert Kawecki Avatar answered Oct 27 '25 06:10

Robert Kawecki



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!