Problem Statement
I am working on an integration that will authenticate with a token. I need to pass it via header as follows:
"Authorization": "Token abcdefghijklmnopqrstuvwxyz"
I also need to merge some data into the endpoint. I have considered the following options for storage of the token(s):
- Custom Setting
- Custom Object
- Custom Metadata Type
- Named Credential
My main question is if it is possible/reasonable to use Named Credentials
to store tokens.
Assessment
Custom Setting
Simple, lightweight, and flexible, this approach is the easiest to get off the ground.
Pros
- Does not require any query to access the data
- Only Users with
Customize Application
can see the data - Anyone can access the data via
Apex
when making the callout - Can configure to store any desired authentication mechanism
Cons
- No encryption (?)
Custom Object
If encryption of the token is critical, we could roll out a Custom Object
to store our tokens. This seems like a really ham-handed approach and I would like to avoid it if at all possible
Pros
- Flexible configuration
- Encryption
Cons
- All users need read access or the code needs to run
without sharing
- Requires a query to access the data
Custom Metadata Type
This option doesn't really seem to have any advantages over using a Custom Setting
or Custom Object
.
Pros
- Flexible configuration
Cons
- No Encryption
- Requires a query to access the data
Named Credentials
This option seems really promising, but based on my reading so far, it's not clear to me if it has the flexibility I need. After navigating to Setup
> Administration
> Security Controls
> Named Credentials
and clicking on the New Named Credential button, I got this screen:
Setting the Authentication Protocol
to Password Authentication doesn't seem like a good fit, but it was hard to hunt down how to set up an Authentication Provider
. It doesn't seem to actually be a field on the NamedCredential
object (the only lookup fields in the describe are CreatedById
and LastModifiedById
).
I found an article that purports to describe how to Create a Custom External Authentication Provider, but its description of how to navigate to the setup is outdated. It recommends:
From Setup, enter Auth. Providers in the
Quick Find
box, then select Auth. Providers.
There's no such item in my setup menu. The closest I could find was Identity Provider
, which requires me to set up My Domain
before I can use it. This option seems like it has way more side effects than I would like.
Pros
- Purpose built for authentication procedures
Cons
- Unclear if it supports token authentication
- Unclear if it supports merging data into the URL
- Requires
My Domain
(?)
Questions
- Can
Named Credentials
be used to support token based authentication?- Is it necessary to set up
My Domain
in order to do so?
- Is it necessary to set up
- Is there really any worry about standard users seeing the token values?
- If stored in a
Custom Setting
, only users with theCustomize Application
permission can access the data through the UI. These users should be highly trusted already.
- If stored in a
- Is there any benefit to encrypting the token?