Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Here is a step-by-step guide how to set it up in the Salesforce.

Salesforce: Create New Certificate

You need a certificate with the Key Size 2048.

...

Pricefx: Create Configuration for External JWT Tokens

  1. Download a certificate from the Salesforce and export the public key from it.

    Code Block
    openssl x509 -pubkey -noout -in pricefx_jwt_2048.crt > pricefx_jwt_2048.pubkey
  2. Create one line string from the public key.

    Code Block
    awk 'NF {sub(/\r/, ""); printf "%s\\n",$0;}' pricefx_jwt_2048.pubkey
  3. Take the output and create a new configuration input in the Advanced Configuration Section with the name externalJWTConfiguration and put the public key there and set the permissions.

    Code Block
    {
      "entries" : {
        "salesforceScratch" : {
          "publicKey" : "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAjeJy7gBcWkF1PkTyjbtX\n7SNWVpWujDEZ3PrMx7a2B7y/wAb7lB40ROY4hoImM9QxcwBRaEU2kNtWqvyaUY7N\nYdqXSH+Qa75oBCCvtjjZJxO/vDz9rMyu7fQlU7nPJM8yly7c5E2TvcEWQMjbL6Yn\nbuwNPlBbzAi3u5lMf4pISvswV4aSs6X4rFg3cQTDlctKpv3FULv701ZD7Oqu14cJ\nRikCM253Am0+3KPGxmX+vdhNI9oEMt7eIEvWh+ky5p7hZTdV8s+mez/y5JnTkcy/\nwuhMmQ5Nkp2yJV217JsILNW2EZZDKz0zTIjfD7VlzsL0dzIUm+LQHyr4QdrpzW0u\nlwIDAQAB\n-----END PUBLIC KEY-----\n",
    "permissions" : ["PRICINGFORMULA_EXECUTE"]
        }
      }
    }

...

Salesforce: Make Call to Pricefx Endpoint

  1. Generate named credentials with no authentication.

    1. Put there the URL you want to call.

      Code Block
      https://e2e.pricefx.eu/pricefx/seeddata/formulamanager.executeformula/SalesforcePackage_getPrice

  2. Write the Apex Code that will authorize with JWT Token.

    Code Block
    languagejava
        Auth.JWT jwt = new Auth.JWT();
        jwt.setSub('topon');               //username of the pricefx user
        jwt.setAud('e2e');                 //cluster name
        jwt.setIss('salesforceScratch');   //name of the external configuration
    
        Map<String, Object> claims = new Map<String, Object>();
        claims.put('partition', 'seeddata'); //partition name
    
        jwt.setAdditionalClaims(claims);
        Auth.JWS jws = new Auth.JWS(jwt, 'pricefx_jwt_2048');
    
        String token = jws.getCompactSerialization();
        System.debug('------------- > : ' + token);
    
        HttpRequest req = new HttpRequest();
        req.setEndpoint('callout:pfx_getPriceNoAuth');
        req.setMethod('POST');
        Http http = new Http();
        req.setHeader('Authorization', 'BEARER salesforceScratch;' + token);
        req.setTimeout(120000);
        req.setBody('{"data": {"SFProduct": "Mercedes"}}');
    
        HTTPResponse res = http.send(req);
        System.Debug('#### response:getBody:  ' + res.getBody());
        System.Debug('#### response:getStatusCode ' + res.getStatusCode());
        System.Debug('#### response:getStatus ' + res.getStatus());
        System.Debug('#### response:getStatusCode ' + res.getHeaderKeys());
    
        //System.debug(res.getBody());
    
        if (res.getStatusCode() == 200) {
          return res.getBody();
        }

  3. Call the APEX code and see the debug in the Salesforce Develop Console.

  4. You can validate the JWT token.

...