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

Client certificate #284

Closed
corporatepiyush opened this issue Apr 4, 2016 · 9 comments
Closed

Client certificate #284

corporatepiyush opened this issue Apr 4, 2016 · 9 comments

Comments

@corporatepiyush
Copy link

I am using axios on node.js 4.2.x. how do i mention SSL CA certificate for connecting to one of the secured services ?

Can anybody point me to an example working code ?

@nickuraltsev
Copy link
Member

You should be able to use a custom Agent as follows:

var agent = new https.Agent({ 
  ca: fs.readFileSync('ca.pem') 
});

axios.get(url, { agent: agent });

// or 

var instance = axios.create({ agent: agent });
instance.get(url);

Hope it helps!

@corporatepiyush
Copy link
Author

In my case, its a .crt file which has bunch of certificates in it from Godaddy.
when i try to do follow the example code @nickuraltsev mentioned, i get following error.

{ [Error: unable to get local issuer certificate] code: 'UNABLE_TO_GET_ISSUER_CERT_LOCALLY' }

@nickuraltsev
Copy link
Member

axios uses https module under the hood. All certificate related config parameters are passed to https. You can even configure https directly:

https.globalAgent.options.ca = fs.readFileSync('ca.pem'); // Note: this is a global setting

If you need help with using an SSL certificate with https module, please ask a question on StackOverflow.

@mzabriskie mzabriskie changed the title Client certificate Client certificate Apr 11, 2016
@voraparth91
Copy link

I am trying to run this project in browser. I cannot find https module available. Can you tell me how this was made possible?

@nickuraltsev
Copy link
Member

@voraparth91 You can configure axios to use specific certificates in Node.js, but not in browsers.

@voraparth91
Copy link

@nickuraltsev Is there any other way you can suggest me where I can configure specific certificates in browser for XHR requests?

@zatziky
Copy link

zatziky commented Dec 7, 2016

Careful, the correct way to assign agent is by using the field httpsAgent.

const instance = axios.create({ httpsAgent: agent });

@alterhu2020
Copy link

alterhu2020 commented Aug 4, 2017

Try below code worked ,thanks team.

const Agent = new https.Agent({
  rejectUnauthorized: false
})
const instance = axios.create()
// instance.defaults.baseURL = `http://${process.env.HOST || 'localhost'}:${process.env.PORT || 3000}`
instance.defaults.httpsAgent = Agent
// instance.defaults.headers.common['Authorization'] = 'Basic YWx0ZXY='
// instance.defaults.timeout = 14500

@LNyears
Copy link

LNyears commented May 20, 2019

In my case, its a .crt file which has bunch of certificates in it from Godaddy.
when i try to do follow the example code @nickuraltsev mentioned, i get following error.

{ [Error: unable to get local issuer certificate] code: 'UNABLE_TO_GET_ISSUER_CERT_LOCALLY' }

In my case, its a .crt file which has bunch of certificates in it from Godaddy.
when i try to do follow the example code @nickuraltsev mentioned, i get following error.

{ [Error: unable to get local issuer certificate] code: 'UNABLE_TO_GET_ISSUER_CERT_LOCALLY' }

I also encountered this problem, can you tell me how you solved it?

@axios axios locked and limited conversation to collaborators May 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants