Loopback4 calling HTTPS/REST service with self signed certificate

257 Views Asked by At

How do I call https/rest endpoint with self signed certificate in Loopback4 with OpenApi connector? Is there any option to allow such certificate?

When I try to call the service.operation(), I get following exception:

Unhandled error in GET /user/8f9d1e34-c340-4ebe-af11-fa0c4575f676: 500 FetchError: request to https://localhost:8243/scim2/1.0.0/Users/8f9d1e34-c340-4ebe-af11-fa0c4575f676 failed, reason: unable to verify the first certificate
    at ClientRequest.<anonymous> (D:\DEV_BTC\GIT\Foton\PIX\application\composite-services\perfil-usuario-ms\node_modules\node-fetch\lib\index.js:1461:11)
    at ClientRequest.emit (events.js:315:20)
    at TLSSocket.socketErrorListener (_http_client.js:426:9)
    at TLSSocket.emit (events.js:315:20)
    at emitErrorNT (internal/streams/destroy.js:92:8)
    at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
    at processTicksAndRejections (internal/process/task_queues.js:84:21)

Documentation for REST Connector mentions a parameter called "strictSSL": false to allow self-signed SSL certificates. Is there something similar to OpenAPI connector?

Thank you!

1

There are 1 best solutions below

0
On

After opening a bug report that turned into question and then a feature request, Loopback's team created a new version of loopback-connector-openapi to handle this option.

Basically you need to add this option to your datasource config:

const config = {
  (...)
  httpClientOptions: {
    agent: new https.Agent({rejectUnauthorized: false}),
  }
  (...)
}