I need to integrate with a service that uses an authentication flow I'm not familiar with and wondering can I use Named Credentials with it?
The flow requires that I first get a JWT token by passing a username & password in a JSON body. Then I can use that as a regular bearer token.
- Get token, which returns
{"securityToken": "TOKEN"}
curl --request POST \
--url https://SERVICE_URL/token \
--header 'Content-Type: application/json' \
--data '{
"Username": "USERNAME",
"Password": "PASSWORD"
}'
- Call secured endpoint
curl --request GET \
--url https://SERVICE_URL/record \
--header 'Authorization: Bearer TOKEN'
Is this a common authentication flow and, if so, is there a common name for it?
Can I Use Salesforce Named Credentials with this kind of flow or will I need to manually call out for the token?
Best Answer
Named Credentials cannot be used to handle this authentication flow, but the feature can be leveraged to get the token without having to resort to something like Custom Settings for storing the username & password.
Create a Named Credential specifically for getting the token.
Anonymous Apex