Before you start
Make sure you have the following before proceeding:- Client certificate: issued by Fexco after you submit a CSR. See Set up a client certificate.
openssl: required to generate a JWT from the command line. Pre-installed on macOS and most Linux distributions. On Windows, install it via OpenSSL for Windows or use Windows Subsystem for Linux (WSL).
Component of a JWT
A JWT consists of three Base64URL-encoded parts:- The header
- The payload
- A signature joined by dots.
jsonwebtoken
for Node.js, PyJWT for Python, or java-jwt for Java) to handle
signing and assembly.
JWT header
The header identifies the signing algorithm and embeds your client certificate so Fexco can verify the token.JWT payload
The payload carries request metadata and a digest of the request body that Fexco uses to detect tampering in transit.JWT signature
The signature is computed by signing the Base64URL-encoded header and payload, joined by a dot, with your private key using RS256 (RSA with SHA-256). This is the same private key you generated when creating your certificate signing request (CSR). See Set up a client certificate.x5c header field. If the signature does not match, the
request is rejected.
Build the JWT generation script
The following steps walk through each part of the script. A complete, ready-to-run version is available in the Bash example below.1
Define a base64url helper
JWT encoding requires Base64URL. Standard Base64 with
+ and / replaced
and padding stripped. Define this helper once at the top of your script.2
Encode the client certificate
The certificate must be Base64-encoded before it can be embedded in the JWT
header. Replace
YOUR_ACQUIRER_ID with your three-letter acquirer ID.3
Build the JWT header
Assemble the header JSON with the signing algorithm, token type, API
version, key ID, and encoded certificate.
4
Hash the request body
Compute a SHA-256 digest of the exact JSON body you will send. This lets
Fexco detect any tampering in transit.
The
request_body defined here is used only to compute the digest — the
script does not make an API call. You must pass the exact same JSON as the
request body in your API call. If the two differ, the digest will not match
and the request will be rejected.5
Build the JWT payload
Assemble the payload with your client identifiers, timestamps, and the body
digest. The token expires 5 minutes after issue.
6
Base64url-encode the header and payload
Encode both parts so they are safe to use in the token string.
7
Sign the token
Sign
header.payload with your private key using RS256. Replace
YOUR_ACQUIRER_ID with your acquirer ID.8
Assemble the JWT
Join the three parts with dots. The resulting
$jwt_token is ready to use
as a Bearer token.Bash example
The script below generates a complete JWT and is useful for manual testing and debugging. Before running it, replace the following placeholders with your own values:YOUR_ACQUIRER_ID: your three-letter acquirer ID (for example,TST)YOUR_KEY_ID: the key identifier for your signing certificate, provided by FexcoYOUR_CLIENT_SYSTEM: a label identifying your system, used for troubleshootingYOUR_CLIENT_ID: your API client identifier, provided by Fexco
request_body value with the exact JSON body you will
send in your API request, the script uses it to compute the digest embedded in
the JWT. The script requires openssl, which is pre-installed on macOS and most
Linux distributions.
Make an authenticated request
Once you have a JWT, pass it as aBearer token in the Authorization header
of your API request. For a full walkthrough of request parameters and response
handling, see Request a DCC offer (Rate Service Connect).
For the complete list of request headers and endpoint details, see the
API reference.
Security best practices
- Keep token expiry short. Set
expto no more than 5 minutes afteriat. Each request uses a new JWT, so long-lived tokens are unnecessary and increase risk. - Always include the request body digest. The
digestclaim ensures the request body has not been tampered with in transit. - Use HTTPS. All communication with the Rate Service Connect API must use HTTPS with TLS 1.2 or higher.
Next steps
- Request a DCC offer (Rate Service Connect): make your first authenticated rate request using the Rate Service Connect API.
- Error handling: error response format and authentication-related error codes.
