contiamo / restful-react

A consistent, declarative way of interacting with RESTful backends, featuring code-generation from Swagger and OpenAPI specs 🔥
MIT License
1.87k stars 109 forks source link

Support self signed certificates #345

Open daniellwdb opened 3 years ago

daniellwdb commented 3 years ago

Is your feature request related to a problem? Please describe. I finally set up a dotnet core API with swagger and local https using a self signed certificate. Now I tried to consume the generated swagger.json so I created a command:

{
  "generate-fetcher": "restful-react import --url https://localhost:5001/swagger/v1/swagger.json --output src/generated/fetchers.tsx"
}

Unfortunately this results in a clear error

❯ npm run generate-fetcher                    

> todo-app@0.1.0 generate-fetcher
> restful-react import --url https://localhost:5001/swagger/v1/swagger.json --output src/generated/fetchers.tsx

Error: self signed certificate

Describe the solution you'd like It would be nice if we can somehow trust this certificate, however I lack knowledge to get a clear idea of what this would look like.

Describe alternatives you've considered The current workaround is to set the NODE_TLS_REJECT_UNAUTHORIZED environment variable

{
  "generate-fetcher": "NODE_TLS_REJECT_UNAUTHORIZED='0' restful-react import --url https://localhost:5001/swagger/v1/swagger.json --output src/generated/fetchers.tsx"
}
fabien0102 commented 3 years ago

Good to know, I think we should just add your workaround in the README.md I don't really better idea for this edge case 😅

daniellwdb commented 3 years ago

It seems like another solution could be to add strictSSL: false to the urlSpecReq options, maybe this property could be added dynamically with a flag so that people don't have to depend on cross-env or set the environment variable globally, I did some reading and it's also possible to pass certificate options to the request options but I don't think it's easy to implement this because there are different kinds of certificates, .pfx must be parsed before used but even after I did that I couldn't get it to work, maybe somebody wants to look into that in the future