Search code examples
angularsslasp.net-corecertificatecertificate-authority

I have created an SSL/TLS certificate for localhost for my backend ASP.NET Core web api, can I share it with my front-end Angular app?


I have a backend server running in ASP.NET Core. There I have generated an SSL/TLS certificate and it was automatically added to the trusted CA on my machine. I want to serve my angular app over SSL/TLS also, for local development. Angular front end is running on localhost as well just a different port. Do I have to create a different certificate for my Angular app since it is on a different port? (Does the difference in port matter? Is it considered a different domain at that point?). If I can share it, how would I go about doing it?

Thanks


Solution

  • for the certificate it doens't make a difference regarding the port. you just secure your resources in your angular and asp.net with this certificate. make sure all the services you try to connect to are on https otherwise your browser will block the outgoing request. the only place where the port is of importance would be in the security policies (content security policies) against XSRF, XSS, ...

    just add something like the following in package.json:

    "scripts": {
        "start": "ng serve --ssl --ssl-key c:\\certificates\\localhost.key  --ssl-cert c:\\certificates\\localhost.crt --host 0.0.0.0"
    

    note: --host 0.0.0.0 is only needed if you want to access the dev server from outside localhost...

    In your browser/dev machine add it to the trusted CA. here's a reference on how to do it for chrome:

    https://support.securly.com/hc/en-us/articles/206081828-How-to-manually-install-the-Securly-SSL-certificate-in-Chrome