How to set up mTLS

Lean Data API illustration


Calls from your backend to Lean are required to be made over Mutual Transport Layer Security (mTLS). mTLS is a certificate based authentication protocol that replaces oAuth public / private keys. Instead of sending a private key, you send your certificate with your calls to the Lean servers to authenticate.

If you'd like to learn more about what mTLS does and how it works you can learn more here.

Getting your certificates

When you create application at you will be able to download two files from the authentication section of the developer portal. By clicking 'generate new certificate' a zip folder containing my_app_private_key.pem file and a my_app_cert.crt file will be downloaded.

Within the UI on you should also download the Lean certificate chain. To do this click the button labelled 'Certificate chain'. This should trigger a further download of a zipped folder containing lean_public_cert_chain.pem.

With the above complete you should now have three files.

Node example


const fs = require('fs')
const https = require('https')
const axios = require('axios')
const httpsAgent = new https.Agent({
// This is your application certificate
cert: fs.readFileSync('cert.crt'),
// This is your private key associated with application certificate
key: fs.readFileSync('key.pem'),
// This is Lean's public certificate chain.
ca: fs.readFileSync('ca.pem'),
const start = async () => {
try {
const request = await axios({
method: 'post',
headers: {
'lean-app-token': 'LEAN_APP_TOKEN',
// You can change the end point per your need. This endpoint is good for
// testing mTLS
url: '',
withCredentials: true,
jar: true,
} catch (error) {

Go example


package main
import (
var (
// cert file MUST be a concatenation of certificate provided by Lean AND the Lean public certificate chain!!!
certFile = flag.String("cert", "cert_and_cert_chain.crt", "Your application certificate provided by Lean concatenated with cert chain")
keyFile = flag.String("key", "key.pem", "Your private key attached to application certificate")
caFile = flag.String("CA", "ca.pem", "Lean's public certificate chain")
func main() {
// Load client cert
cert, err := tls.LoadX509KeyPair(*certFile, *keyFile)
if err != nil {
// Load CA cert
caCert, err := ioutil.ReadFile(*caFile)
if err != nil {
caCertPool := x509.NewCertPool()
// Setup HTTPS client
tlsConfig := &tls.Config{
Certificates: []tls.Certificate{cert},
RootCAs: caCertPool,
transport := &http.Transport{TLSClientConfig: tlsConfig}
client := &http.Client{Transport: transport}
// Please change the end point as required.
res, err := client.Get("")
if err != nil {
contents, err := ioutil.ReadAll(res.Body)

Python example


import json
import requests
getBanksUrl = ''
headers = {'lean-app-token': 'YOUR_APP_TOKEN', 'Content-Type': 'application/json'}
result = requests.get(
cert=('your_apps.crt', 'your_apps.pem'), # Use the path to your own certificate and private key here
if (result.status_code == 200) :
print (result.json())
else :
print (f"Error - {result.json()['status']}: {result.json()['message']}")


While your application does not have Production access, you can check your mTLS configuration by making a GET request to

If your application is configured correctly the API will respond with an INSUFFICIENT_ACCESS_LEVEL error. If it doesn't you'll get a connection error that depends on your programming language / framework.