Skip to main content
Mangopay must ensure that your platform’s interactions with its services are compliant with SCA. In cases where your platform is taking SCA-triggering actions under proxy from users, your platform needs to use a second authentication factor. The API key that your platform uses to authenticate API calls serves as a knowledge-based factor. The second factor Mangopay uses is mTLS authentication, which is a possession-based factor that your platform needs to set up and integrate as described below. Integration of mTLS authentication is only necessary if your platform is using proxy management.

Mutual TLS authentication

Mutual Transport Security Layer (mTLS) is a standard protocol that enables two-way secure authentication between your platform’s server and Mangopay’s server, ensuring both parties are authenticated before data is exchanged. The system works using public-key cryptography, which involves a public-private key pair – the private key is a secret that you must store securely like your existing API key.

Overview

For your platform, mTLS authentication requires you to:
  1. Generate a private key
  2. Generate a CSR
  3. Request a certificate in the Mangopay Dashboard using the CSR and download it
  4. Integrate mTLS in the SDK using the certificate, your private key, and a new base URL
  5. Renew your certificate before it expires after 12 months
An overview of the whole process is given in the diagram below:

1. Generate a private key

Your platform will need to generate a private key. You can do this using OpenSSL, which is a widely used software library for cryptographic functions. The following command, for example, creates a file named private.key in the directory where the command is run. This command generates an RSA key, which uses a popular algorithm for public-key cryptography. The length of the key is 2048 bits, a common standard.
openssl genrsa -out private.key 2048
You should generate one key for Sandbox and one for Production to enhance security.
Note - Store the private key securelyThe private key is a long string or small file and you must store it securely, in the same way as an API key.Do not share the private key with Mangopay. Only the CSR is shared with Mangopay.

2. Create a CSR

Once you have the private key, you can use it to generate a Certificate Signing Request (CSR). A CSR is an encoded file that contains a public key and information about your server, and your private key is used to create a secure digital signature. The OpenSSL commands below create a CSR called client.csr using the private.key for a generic ClientId. Before running the commands, update the variables for your file names and Client ID. You can find the same commands with your ClientId prepopulated in the Mangopay Dashboard (Developers > mTLS certificates).

Linux / MacOS

Sandbox
openssl req -new -key private.key -out client.csr \
  -subj "/CN=ClientId.sandbox.mangopay.com/O=Mangopay/C=LU" \
  -addext "subjectAltName=DNS:ClientId.sandbox.mangopay.com" \
  -addext "extendedKeyUsage=clientAuth"
Production
openssl req -new -key private.key -out client.csr \
  -subj "/CN=ClientId.prod.mangopay.com/O=Mangopay/C=LU" \
  -addext "subjectAltName=DNS:ClientId.prod.mangopay.com" \
  -addext "extendedKeyUsage=clientAuth"

Windows (PowerShell, CMD, Git Bash)

Sandbox
openssl req -new -key private.key -out client.csr -subj "/CN=ClientId.sandbox.mangopay.com\O=Mangopay\C=LU" \
  -addext "subjectAltName=DNS:ClientId.sandbox.mangopay.com" \
  -addext "extendedKeyUsage=clientAuth"
Production
openssl req -new -key private.key -out client.csr -subj "/CN=ClientId.prod.mangopay.com\O=Mangopay\C=LU" \
  -addext "subjectAltName=DNS:ClientId.prod.mangopay.com" \
  -addext "extendedKeyUsage=clientAuth"

3. Request a certificate

Once you have your CSR, you can use it to request and download the certificate:
  • Connect to the Mangopay Dashboard
  • Navigate to Developers > mTLS certificates
  • Click Request certificate in the top right
  • Paste your CSR content or upload the .csr file
  • Click Generate certificate
  • On the mTLS certificates page, navigate to the Certificates tab, where you should see your certificate as ACTIVE
  • To download the certificate, hover over the table line, click the kebab icon (⋮) on the right, and click Download
The certificate file that you download is a .pem file containing only the certificate. You will need both the .pem file and your private .key file from Step 1 to complete the SDK integration.

4. Integrate mTLS in the SDK

Mangopay’s server-side SDKs support mTLS authentication as an additional authentication layer on top of the API key and Client ID. The SDKs use TLS 1.2+ for mTLS, which is required by the API.

Secrets management

Caution – Manage your secrets safelyIn your integration, ensure you manage all secrets securely, including your API key, Client ID, private .key, and .pem certificate.
Where possible, the SDKs allow you to use Base64-encoded strings, so you can encode the content of the .pem file and .key file to store then in your secrets manager, and use the variables in your environment. The SDKs contain features to simplify integration and Sandbox testing, including handling local file paths. If two sets of SDK properties are available, the file-path ones take precedence to facilitate testing. In Production, you must ensure your secrets are handled safely, using encoded variables and dedicated secrets managers.

Prerequisites

To use mTLS authentication in the SDK you need:
  • The mTLS certificate, which is the .pem file downloaded from the Mangopay Dashboard
  • The private key (.key file) used to generate the CSR which you used to request the certificate
The integration guidance differs depending on your SDK language. The SDK version on which the mTLS features were implemented is given in each case.
Minimum Java SDK version: 2.61.0

Set the base URL for mTLS

Using mTLS authentication requires your integration to call a base URL with a different hostname from the standard API:
  • Sandbox: https://api-mtls.sandbox.mangopay.com
  • Production: https://api-mtls.mangopay.com
If using mTLS, your integration should use the api-mtls URLs for all API calls, including OAuth token generation.Caution: Ensure you set the mTLS base URL, as shown in the configuration examples below. If you don’t, Mangopay will not receive your mTLS certificate correctly and your integration will result in an error (when mTLS is enforced).For the Java SDK, set the base URL using the setBaseUrl() method on the Configuration object attached to your MangoPayApi instance:
MangoPayApi api = new MangoPayApi();
api.getConfig().setBaseUrl("https://api-mtls.sandbox.mangopay.com/");

Convert the certificate to PKCS12

For the Java SDK, you need to convert your certificate to the PKCS12 format. For Java, the .p12 file format is more common (rather than .pfx).You can do this using OpenSSL, for example:
openssl pkcs12 -export \
  -in certificate.pem \
  -inkey private.key \
  -out client.p12 \
  -name "client-cert" \
  -passout pass:your-cert-password

Configure the SDK’s mTLS properties

The Java SDK uses the standard java.security.KeyStore with the p.12 file to manage mTLS certificates.Two setters on com.mangopay.core.Configuration control mTLS:
SetterTypeDescription
setKeyStore(KeyStore)java.security.KeyStoreA loaded PKCS12 keystore holding the client certificate and private key.
setKeyStorePassword(char[])char[]Password that protects the entry inside the keystore.
Both methods are synchronized. This means that they automatically invalidate the cached SSLContext so that the following request rebuilds it with the new values.
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.security.KeyStore;

KeyStore keyStore = KeyStore.getInstance("PKCS12");
try (InputStream ks = Files.newInputStream(Paths.get("client.p12"))) {
    char[] password = "your-cert-password".toCharArray();
    keyStore.load(ks, password);
}
api.getConfig().setKeyStore(keyStore);
api.getConfig().setKeyStorePassword("your-cert-password".toCharArray());

5. Renew your certificate

The .pem certificate provided by Mangopay is valid for 12 months, after which point it expires. Before it expires, you need to generate a new one following the same process as above, starting with a new private key.