Integrating the mTLS certificate factor required for platforms taking SCA action under proxy
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 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.
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.
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).
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.
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.
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.
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
Note – Use mTLS hostname for all API callsIf using mTLS, your integration should use the api-mtls base URLs for all API calls, including OAuth token generation.
Caution – Set the mTLS base URLEnsure you set the Sandbox or Production mTLS base URL with api-mtls in the hostname. 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/");
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:
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:
Setter
Type
Description
setKeyStore(KeyStore)
java.security.KeyStore
A 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.
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
Note – Use mTLS hostname for all API callsIf using mTLS, your integration should use the api-mtls base URLs for all API calls, including OAuth token generation.
Caution – Set the mTLS base URLEnsure you set the Sandbox or Production mTLS base URL with api-mtls in the hostname. 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 .NET SDK, you need to convert your certificate to the PKCS12 format. For .NET, the .pfx file format is more common (rather than .p12).You can do this using OpenSSL, for example:
The .NET SDK allows you to load Base64-encoded strings from your environment variables. You can also load locally stored file paths, which may be useful during testing.Caution: The file path properties take precedence if both are set.
When your .pfx certificate is stored as a BAse64-encoded string in a secrets manager, you can load it using the ClientCertificateString, along with ClientCertificatePassword for its password (non-encoded).Best practice: Use this option in Production.
using MangoPay.SDK;using MangoPay.SDK.Core;var api = new MangoPayApi();api.Config.ClientId = "your-mangopay-client-id";api.Config.ClientPassword = "your-mangopay-api-key";api.Config.BaseUrl = "https://api-mtls.sandbox.mangopay.com"; // mTLS base URL// Base64-encoded PFX/PKCS#12 bytesapi.Config.ClientCertificateString = Environment.GetEnvironmentVariable("CLIENT_PFX_B64");// Optional: password string (omit if the certificate has no password)api.Config.ClientCertificatePassword = Environment.GetEnvironmentVariable("YOUR_CERT_PASSWORD");
If your .pfx and its password are stored locally, for example during testing, you can load them using X509Certificate2.Caution: If the X509Certificate2 property is set, it takes precedence and the ClientCertificateString and ClientCertificatePassword are ignored.
using System.Security.Cryptography.X509Certificates;using MangoPay.SDK;using MangoPay.SDK.Core;var cert = new X509Certificate2("path/to/client.pfx", "your-cert-password");var api = new MangoPayApi();api.Config.ClientId = "your-mangopay-client-id";api.Config.ClientPassword = "your-mangopay-api-key";api.Config.BaseUrl = "https://api-mtls.sandbox.mangopay.com"; // mTLS base URLapi.Config.ClientCertificate = cert;
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
Note – Use mTLS hostname for all API callsIf using mTLS, your integration should use the api-mtls base URLs for all API calls, including OAuth token generation.
Caution – Set the mTLS base URLEnsure you set the Sandbox or Production mTLS base URL with api-mtls in the hostname. If you don’t, Mangopay will not receive your mTLS certificate correctly and your integration will result in an error (when mTLS is enforced).
The Node.js SDK allows you to load Base64-encoded strings from your environment variables. You can also load locally stored file paths, which may be useful during testing.Caution: The file path properties take precedence if both are set.
When your .pem certificate and private .key are stored as encoded strings in a secrets manager, you can load them using the following configuration properties.Best practice: Use this option in Production.
Property
Type
Description
cert
string
Base64-encoded string of the certificate .pem file content.
key
string
Base64-encoded string of the private .key file content.
ca
string (optional)
Base64-encoded string of the private or custom certificate authority, if used.
passphrase
string (optional)
String of the passphrase for an encrypted private key.
If your .pem certificate and private .key are stored locally, for example during testing, you can load them using the following properties.Caution: If the file path properties are set, they take precedence and the Base64-encoded equivalents are ignored.
Property
Type
Description
certFilePath
string
Path to the certificate .pem file.
keyFilePath
string
Path to the private .key file.
caFilePath
string (optional)
Path to the private or custom certificate authority, if used.
passphrase
string (optional)
String of the passphrase for an encrypted private key.
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
Note – Use mTLS hostname for all API callsIf using mTLS, your integration should use the api-mtls base URLs for all API calls, including OAuth token generation.
Caution – Ensure you set the mTLS base URLEnsure you set the Sandbox or Production mTLS base URL with api-mtls in the hostname. If you don’t, Mangopay will not receive your mTLS certificate correctly and your integration will result in an error (when mTLS is enforced).
The PHP SDK allows you to load Base64-encoded strings from your environment variables. You can also load locally stored file paths, which may be useful during testing.Caution: The file path properties take precedence if both are set.
When your .pem certificate and private .key are stored as encoded strings in a secrets manager, you can load them using the following configuration properties.Prerequisite: The Base64-encoded string properties require PHP ≥ 8.1 compiled against libcurl ≥ 7.71.0.If this prerequisite is not met, the SDK will throw an exception at runtime because of the CURLOPT_SSLCERT_BLOB and CURLOPT_SSLKEY_BLOB used under the hood.
Property
Type
Description
ClientCertificateString
string
Base64-encoded string of the certificate .pem file content.
ClientCertificateKeyString
string
Base64-encoded string of the private .key file content.
ClientCertificateKeyPassword
string (optional)
String of the passphrase for an encrypted private key.
$api = new MangoPay\\MangoPayApi();$api->Config->ClientId = 'your-mangopay-client-id';$api->Config->ClientPassword = 'your-mangopay-api-key';// mTLS base URL$api->Config->BaseUrl = 'https://api-mtls.sandbox.mangopay.com';// Base64-encoded .pem certificate content$api->Config->ClientCertificateString = 'MANGOPAY_PEM_B64'// Base64-encoded private .key content$api->Config->ClientCertificateKeyString = 'MANGOPAY_KEY_B64'// Optional: passphrase if the private key is password-protected$api->Config->ClientCertificateKeyPassword = 'YOUR_CERT_PASSWORD';
If your .pem certificate and private .key are stored locally, for example during testing, you can load them using the following properties.Caution: If the file path properties are set, they take precedence and the Base64-encoded equivalents are ignored.
Property
Type
Description
ClientCertificatePath
string
Path to the certificate .pem file.
ClientCertificateKeyPath
string
Path to the private .key file.
ClientCertificateKeyPassword
string (optional)
String of the passphrase for an encrypted private key.
$api = new MangoPay\\MangoPayApi();$api->Config->ClientId = 'your-mangopay-client-id';$api->Config->ClientPassword = 'your-mangopay-api-key';// Path to the .pem certificate file$api->Config->ClientCertificatePath = '/path/to/certificate.pem';// Path to the private .key file$api->Config->ClientCertificateKeyPath = '/path/to/private.key';// Optional: passphrase if the private key is password-protected$api->Config->ClientCertificateKeyPassword = 'your-cert-password';
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
Note – Use mTLS hostname for all API callsIf using mTLS, your integration should use the api-mtls base URLs for all API calls, including OAuth token generation.
Caution – Set the mTLS base URLEnsure you set the Sandbox or Production mTLS base URL with api-mtls in the hostname. If you don’t, Mangopay will not receive your mTLS certificate correctly and your integration will result in an error (when mTLS is enforced).
The Python SDK allows you to load the .pem and .key file paths in the global configuration or in the per-request handler.
Property (global / per-request)
Type
Description
mtls_cert / cert
string
Path to the certificate .pem file.
mtls_private_key / key
string
Path to the private .key file.
Caution: The per-request properties cert and key take precedence if set and the global ones are ignored (mangopay.mtls_cert and mangopay.mtls_private_key).The certificate files must be accessible at runtime; the SDK does not validate their content at initialization time.When both are provided, the SDK sets session.cert = (cert, key) on the underlying requests.Session. If a combined certificate is provided (bundling the key), the SDK sets session.cert = cert.
The global properties allow you to set the certificate and key before making any API calls. The certificate is used for all requests made through the default handler.
Caution: The per-request values take precedence over the global values.Each APIRequest instance maintains its own requests.Session, so mTLS certificates are scoped to that instance and do not leak between handlers.
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
Note – Use mTLS hostname for all API callsIf using mTLS, your integration should use the api-mtls base URLs for all API calls, including OAuth token generation.
Caution – Set the mTLS base URLEnsure you set the Sandbox or Production mTLS base URL with api-mtls in the hostname. If you don’t, Mangopay will not receive your mTLS certificate correctly and your integration will result in an error (when mTLS is enforced).
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.