Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to call API with certificates #41

Open
guptapranay opened this issue Jul 11, 2019 · 1 comment
Open

Unable to call API with certificates #41

guptapranay opened this issue Jul 11, 2019 · 1 comment

Comments

@guptapranay
Copy link

We are unable to make API call with certificates which we are using in our api framework with sync-request node module.

process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0' : We don't want to use this as we have certs available to us. Any suggestions - how to make sync-request work with certs?

@Twathik
Copy link

Twathik commented Oct 24, 2021

In case this is still relevant

import fs from 'fs'
import http from 'http'
import https from 'https'

const httpsAgent =
  process.env.NODE_ENV === 'production'
    ? new https.Agent({
        /* requestCert: true,
    rejectUnauthorized: false, */
        ca: fs.readFileSync('./keys/ca.pem'),
        cert: fs.readFileSync('./keys/server.pem'),
        key: fs.readFileSync('./keys/server-key.pem'),
        dhparam: fs.readFileSync('./keys/dhparam.pem'),
        keepAlive: true,
      })
    : new http.Agent({ keepAlive: true })


... your  async function 
const file = await thenRequest('GET', downloadUri, { agent:  httpsAgent})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants