HTTP with client certificate auth request

Describe the issue/error/question

I need to be able to make an http call with a “client certificate auth”. How can we o this in n8n cloud?

Was able to do so in make.com and using function node in self hosted version of n8n enabling axios and https libs
However the ideal scenario would be to have this auth method in the core code, same as you did for oauth2 and other auth methods.

Below the example code in the function node:

const https = require('https');
const axios = require('axios');

// agent
const agent = {
    cert: "-----BEGIN CERTIFICATE-----\nABCD\nABCD\nABCD\nABCD\n-----END CERTIFICATE-----", //Saved in n8n credentials module
    key: "-----BEGIN CERTIFICATE-----\nABCD\nABCD\nABCD\nABCD\n-----END CERTIFICATE-----", //Saved in n8n credentials module
    rejectUnauthorized: false,
    keepAlive: true,
    passphrase: "andres"
    }

// configure request
const options = {
    url: "https://69bbef42e767352de8881ad0ca337f09.m.pipedream.net",
    headers: {'Content-Type': 'application/x-www-form-urlencoded','Accept':'application/json','Authorization':'Bearer '+{{ACCESS.TOKEN}},'X-Client-Id':'OTHERCLIENTID'},
    method: 'POST',
    data : 'grant_type=client_credentials&scope=andresScope&client_id=XYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYGx&client_secret=IJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJA',  ////Saved in n8n credentials module
    httpsAgent : new https.Agent(agent),
}

try {

    const response = await axios(options)
    console.log(response.data);
    return [{ json:response.data }] 
  } 
catch (error) {
//    console.log(error.response.body);
    return [{ json: {'value':'error'} }] 
  }

Below some images on the way make.com resolved this:
Create HTTP type of call specific for cert auth:


Save cert and key in credentials module:

Idea on suggested way to implement in n8n UI

Maybe an extension of this commit?https://github.com/n8n-io/n8n/commit/e29c5975e1f1ad089167df46021203e9f67c8ef1
@jan @RicardoE105

Example from Postman Console:

Hope somebody can help us with this!
@Jon @MutedJam @milorad

Thanks!
Andres

Information on your n8n setup

  • n8n version: 0.203.1
  • Running n8n via [Docker, npm, n8n.cloud, desktop app]: PRO PLAN N8N CLOUD
2 Likes

Hi @pradilla, I’ve asked about using axios in the Function node in the past but the team was hesitant to allow this. So I am afraid your code won’t work on n8n cloud :frowning:

You could try using request-promise-native which is currently whitelisted on n8n cloud, though this will eventually be removed from n8n altogether from my understanding. So your best bet would be to use a self-hosted version of n8n for the time being, and also leave a vote on the corresponding feature request.

1 Like

Ahh, this is quite interesting. I do not think adding to the HTTP node will be too difficult. We have a couple of options here:

Parameters: (Cert, key, and passphrase)

  1. Add the parameters to the generic credentials types.
  2. Add the parameters to the HTTP node as optionals.
  3. Add the parameter to every node under the settings tab.
6 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.