1

I have to connect by Angular 11 to outside service with custom certificate. Client send me certificate, I tested it in postman (add .crt and .key files) and all requests works fine. Problem start on Angular and https request. I get error response in console:

POST https://XXXXX net::ERR_BAD_SSL_CLIENT_AUTH_CERT

I can't find answer where add content from files .crt and .key below piece of my code.

export class RestConnectionService {

  constructor(private httpClient: HttpClient) {
  }

  public send(queryBody: InputAuthBody): Promise<any> {
    return this.httpClient.post(AppSettings.API_URL + 'XXX', queryBody).toPromise();
  }
}
Bartosz Kolej
  • 97
  • 1
  • 12

2 Answers2

0

You can use the ssl, ssl-key and ssl-cert options for ng serve to do that:

For example in your package.json file :

"serve:dev": "ng serve --ssl --ssl-cert ./certificates/localhost.certificate.crt  --ssl-key ./certificates/localhost.private.key"
Michael Desigaud
  • 2,115
  • 1
  • 15
  • 15
  • ng serve --ssl --ssl-cert ./ssl/server.crt --ssl-key ./ssl/server.key and still same problem ;/ – Bartosz Kolej Mar 30 '21 at 12:17
  • No certificate is ok, in other window i have open postman and all requests from postman for the same address are fine. in settings i added CRT file and KEY file for host for tests – Bartosz Kolej Mar 30 '21 at 12:35
  • maybe this post will help you, it seems to be similar issues: https://stackoverflow.com/questions/59352651/angular-default-app-ng-serve-privacy-error-in-chrome-neterr-cert-authority-i – Michael Desigaud Mar 30 '21 at 12:37
0

I had to do connection server to server. nginx with reverse proxy solve my problem nginx conf code part to add cert:

 location /XXXX/XXXX {
        proxy_ssl_certificate        /etc/nginx/certs/XXX.crt;
        proxy_ssl_certificate_key    /etc/nginx/certs/XXX.key;

        proxy_pass   https://XXX:port/XXXXX/XXXX;
    }
Bartosz Kolej
  • 97
  • 1
  • 12