0

I have been working on this for forever now.

Need: Call "...oktapreview.com/oauth2/v1/token" to receive a token for use in future calls. I am able to do this with postman just fine, trying to do the same in Salesforce with Apex or .js via LWC

Basically, I need apex code that can create a JWT and sign it within Salesforce. As done here , JWT Token Exchange setup in Named Credentials for outbound callout , My issue with the above link is, the user references 'okta_cert' for the DevName of his cert, implying that he has uploaded a key for signing the JWT. The key I have for signing is a .pem file that I cannot seem to figure out how to get into salesforce for reference.

If I use the other Cryto.Sign(...) that uses a private key blob, I am getting many different issues related to encoding and decoding the key in base64.

I am able to get a result if I only use the body of the .pem ('MIIEvgIBADANBgk.....'), but the result is wrong. If I try the same with the whole .pem ('-----BEGIN RSA PRIVATE KEY-----\nMIIEv....) then I get a lot of Invalid Crypto Key or Unrecognized base64 character during encoding decoding.

Somebody help pls.

1
  • 1
    Don't need Apex, Named Cred can now do this flow out of the box: salesforce.stackexchange.com/questions/409484/… . As for keys, you'll have to educate yourself on key formats and transformation between these formats, lots of QA&s on StackOverflow and InfoSec SE on this topic. The JKS keystore format required by Salesforce is well documented with one important nuance noted here.
    – identigral
    Commented Nov 30, 2023 at 21:41

0

You must log in to answer this question.

Browse other questions tagged .