0

I have a requirement where I need to generate a new JWT token for authentication but we cannot hard code the signing key in apex or store the signing key in a Custom Metadata or Settings. So wanted to check if Named Credentials be used to store security/signing keys and then can be accessed via apex when generating a new JWT token?

1

1 Answer 1

-1

Named Credentials are a feature in Salesforce that allows you to store the URL and authentication parameters of an external service in one definition, and then use it as the endpoint for callouts. Named Credentials can support different authentication protocols, such as OAuth 2.0, JWT Bearer Token, or Basic Authentication.

However, Named Credentials cannot be used to store security or signing keys for generating a new JWT token in Apex. This is because Named Credentials do not expose the stored credentials to Apex, and only use them internally when making a callout. Therefore, you cannot access the signing key from a Named Credential and use it to create a JWT token in Apex.

Instead, you can use the following methods to store and access the signing key for generating a JWT token in Apex:

  • Use a custom object or a custom setting to store the signing key as an encrypted field. You can then query the field value in Apex and decrypt it using the Crypto class. This method is more secure than hard-coding the signing key in Apex, but it still requires you to manage the encryption and decryption of the key.
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .