How to Authenticate with External JSON Web Token

For a SFDC connected app (and potentially elsewhere), you can use a 3rd-party JSON Web Token for user authentication. Similarly to SAML, there is no need for hard coded per-user credentials, instead a system-to-system trust relation is established using signed tokens.

Configuring the Trust Relationship

The configuration is stored in a per-partition configuration in an advanced configuration option with the name externalJWTConfiguration. You can do the configuration in the Pricefx UI (see JWT Configuration) or you can configure the option manually as described in this section.

The value must be valid JSON: every key and string value in double quotes. The configuration has the following structure:

JSON
{
  "entries": {
    "<externalSystemName>": {
      "publicKey": "<RSA public key in PEM format, as one line with \n line breaks>",
      "permissions": ["<permission name>", "..."]
    }
  }
}

Where:

  • externalSystemName is a JSON compatible name of the external system (i.e., only [A-Za-z0-9], no whitespaces, etc). This name is also used in the bearer auth header (see below). You can add as many external systems as you like, each with an individual name.

  • publicKey is the RSA public key of the external system as a JSON string. Only RSA keys in the -----BEGIN PUBLIC KEY----- format (X.509 SubjectPublicKeyInfo) are accepted. Replace each line break in the key with \n so that the key is one line in the JSON (see Prepare the Public Key).

  • permissions can be null (or omitted) – in that case the trust does not further restrict permissions (= allow all). If there is a list defined, then any API call using that token/config will only be allowed if the endpoint’s permission requirement matches the permissions listed here.
    Important: This list is just an additional filter. I.e., the authenticated user as such needs to have the required permission to begin with. This setting will not add or allow anything the user could do using regular authentication. It can be used to restrict the trust relation to specific API calls only.

Example of a public key:

-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0E9Zp0JNbDaOMqhZd1C+
/FdBTCjza0qXcjTYCbDUeY89qPpwN19QovmehCVGBSFzLOkltx0YmlCkaKLtzqfS
...
... (edited for security reasons)
...
fXr4+6SBmEOVa7RSzoXr3whpdMdKsIvnDCCmT++aJvHBw63ZKGKb8+ZTAXv0z3sm
LDRyhifUmEoJPGWHV6/oxZQiVRapEFe7SiVTbr2IW7OfrdE3DVrioJmATEKgVr5i
zwIDAQAB
-----END PUBLIC KEY-----

Prepare the Public Key

Pricefx accepts only a public key that starts with -----BEGIN PUBLIC KEY-----. Other formats cause every login to fail. If your key is in another format, convert it first:

Your key starts with

Convert it with

-----BEGIN PUBLIC KEY-----

No conversion needed.

ssh-rsa AAAA... (OpenSSH)

ssh-keygen -e -m PKCS8 -f key.pub > key.pem

---- BEGIN SSH2 PUBLIC KEY ---- (for example, exported from PuTTYgen)

ssh-keygen -i -f key.pub > key_openssh.pub and then ssh-keygen -e -m PKCS8 -f key_openssh.pub > key.pem

-----BEGIN RSA PUBLIC KEY-----

openssl rsa -RSAPublicKey_in -in key.pub -pubout -out key.pem

-----BEGIN CERTIFICATE-----

openssl x509 -pubkey -noout -in cert.crt > key.pem

Then convert the key to one line with \n line breaks:

Bash
awk 'NF {sub(/\r/, ""); printf "%s\\n",$0;}' key.pem

Example of a complete configuration value:

JSON
{
  "entries": {
    "SFDC": {
      "publicKey": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0E9Zp0JNbDaOMqhZd1C+\n...\nzwIDAQAB\n-----END PUBLIC KEY-----\n",
      "permissions": ["PRICINGFORMULA_EXECUTE"]
    }
  }
}

The JWT Configuration page in the Pricefx UI writes this JSON for you, so you do not need to quote or escape anything by hand.

Authenticating

Once the trust relationship is configured, you can use it to authenticate API calls. This is done by sending the signed (by the external system possessing the private key part) and compacted JWT token returned by the server in the standard Authorization HTTP header in the following form:

Authorization: BEARER <externalSystemName>;<signed JWT token>

The external system name in the header must match the name in the configuration exactly, including case. If the configuration contains only one external system, you can omit the name and the semicolon: Authorization: Bearer <signed JWT token>.

The JWT token follows standard RFC rules in terms of structure, signature, etc. Please note that only RS256 signature method is supported.

The content of the token consists of three parts with a certain structure:

Header:

{
 "alg": "RS256"
}
  • alg identifies the algorithm used to generate the signature. It must always be set to RS256 – other algorithms are not supported.

Payload:

{
 "sub": "root",
 "iss": "AllowAll",
 "aud": "integration-test",
 "partition": "system"
}
  • sub is the standard subject field of the JWT token. It must contain the loginName of the user.

  • iss is the standard issuer field of the JWT token. It must contain the external system name value (i.e., the same name as in the trust config and in the HTTP header).

  • aud is the standard audience field of the JWT token. It must contain the Pricefx cluster name (for example, e2e-gcp-staging). If you do not know the cluster name, ask Pricefx Support.

  • partition must be the partition in the request URL, and the user given in sub must exist in it.

  • exp (optional, recommended) is the standard expiration time. Pricefx rejects tokens after this time without any clock-skew tolerance, so keep the clocks of both systems synchronized.

Signature

The signature part is a combination of the encoded header, the encoded payload, a secret, the algorithm specified in the header – all that signed.

Troubleshooting

Every failed external JWT login returns the same response: HTTP status 401 with the error message Login failure. The response does not say which check failed. The reason is written only to the Pricefx server log. If the checks below do not reveal the problem, contact Pricefx Support with the time of the request and the partition name.

Pricefx checks the request in the following order. Go through the list until you find the cause:

  1. Configuration exists and is valid JSON: The partition has an Advanced Configuration Option named externalJWTConfiguration and its value is valid JSON with all keys in double quotes.

  2. Header format: The Authorization header is Bearer <externalSystemName>;<token>, or Bearer <token> if there is only one external system.

  3. External system name: The name in the header matches an entry under entries exactly, including case.

  4. Public key format: The publicKey starts with -----BEGIN PUBLIC KEY----- and is an RSA key (see Prepare the Public Key). SSH2, OpenSSH, BEGIN RSA PUBLIC KEY and certificate formats are rejected.

  5. Signature: The token is signed with RS256 by the private key that belongs to the configured public key.

  6. Expiration: The token has not expired (exp).

  7. Audience: aud contains the Pricefx cluster name.

  8. Subject: sub is present and contains the user's login name.

  9. Partition: The partition claim matches the partition in the request URL.

  10. Issuer: iss matches the external system name.

  11. User: The user exists in the partition and is active.

In versions earlier than 17.2, a missing or invalid externalJWTConfiguration returns a server error instead of Login failure, for example jakarta.servlet.ServletException: ... UncheckedExecutionException ... deserialization error. Check items 1 and 4 first if you see this error.

This page covers tokens issued by an external system. If you authenticate with the Pricefx token (X-PriceFx-jwt) from /login/extended or /accountmanager.getjsonwebtoken, you do not need this configuration. See Authentication.