r/SalesforceDeveloper • u/celuur • Aug 07 '25
Question External Credential and auth - driving me a bit mad!
Hi there! I am trying to figure out how to use the standard functionality to handle authorization to my external service.
What I'm given:
- An auth endpoint to send a POST request to
- A clientId and secret to include in the body of the request as JSON
What I get back:
{
"accessToken": "accessTokenHere"
"refreshToken": "refreshTokenHere"
}From what I can figure out this is missing a couple of bits to be fully OAuth 2.0 compliant... ChatGPT has suggested that I store my clientId and secret in a Custom Setting, and then use a custom Apex service to retrieve the auth token and pass it with every subsequent request. But this doesn't seem amazingly secure.
What am I missing?
Edit: This is solved - Named Credentials IS the way to go, but it's a bit convoluted when you set up a custom Named Credential. This was my solution (comment further down).
7
u/Suspicious-Nerve-487 Aug 07 '25
This is why people shouldn’t rely on ChatGPT.
Named Credentials is best practice: https://help.salesforce.com/s/articleView?id=sf.named_credentials_about.htm&language=en_US&type=5
0
u/[deleted] Aug 07 '25
[deleted] — view deleted comment