Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

Now it is possible to authenticate pricefx partition with an external JWT token.

Here is step-by-step documentation on how to set it up in the SF.

Salesforce: Create a new certificate

You need a certificate with the Key Size 2048

Pricefx: Create - create a configuration for external JWT tokens

  1. Download certificate from the SF and export Public key from it

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

    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

    {
      "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 a call to the pricefx endpoint

  1. Generate named credentials with no authentication.

    1. put there URL of the URL you want to call

      1. https://e2e.pricefx.eu/pricefx/seeddata/formulamanager.executeformula/SalesforcePackage_getPrice
  2. Write the Apex Code that will authorize with JWT Token

    1.     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

    1. You can validate JWT token

  • No labels