Loading
Salesforce now sends email only from verified domains. Read More
Set Up and Maintain Your Salesforce Organization
Table of Contents
Select Filters

          No results
          No results
          Here are some search tips

          Check the spelling of your keywords.
          Use more general search terms.
          Select fewer filters to broaden your search.

          Search all of Salesforce Help
          Use Custom Headers for Basic Authentication with Named Credentials

          Use Custom Headers for Basic Authentication with Named Credentials

          Create an external credential with a custom header that uses HTTP Basic authentication.

          Required Editions

          Available in: both Salesforce Classic (not available in all orgs) and Lightning Experience
          Available in: all editions

          The named credentials schema includes support for authentication protocols such as OAuth 2.0 and AWS Signature v4. Some web service providers, however, have their own authentication protocols that use unique headers for authentication. One such protocol is the HTTP Basic authentication scheme, a simple username-password protocol. To connect to an external service using Basic authentication, choose a Custom authentication protocol for your external credential, and use a custom header to authenticate.

          The HTTP Basic authentication scheme uses the Authorization HTTP header, along with a username and password combined using base64 encoding. The username and password are concatenated with a colon (:), then encoded.

          Transforming with base64 (generic)

          For example:

          myUsername:myPassword → base64 encoding → bXlVc2VybmFtZTpteVBhc3N3b3JkCg==

          The username and password can be similarly decoded.

          Decoding with base64 (example)

          Example:

          bXlVc2VybmFtZTpteVBhc3N3b3JkCg== → base64 data decoded → myUsername:myPassword
          Important
          Important

          The Basic system encodes the username and password, but it doesn’t encrypt them. Because the username and password can be decoded by anyone who encounters them, the Basic authentication scheme is only secure when used with SSL encryption (HTTPS/TLS).

          The encoded Basic data goes in the Authentication header as follows.

          GET https://example.com HTTP/1.1
          Authorization: Basic bXlVc2VybmFtZTpteVBhc3N3b3JkCg==

          Create a Custom Header for Basic Authentication

          Both named and external credentials can have custom credentials. To create a custom header for Basic authentication, use an external credential.

          Here’s a general outline of how to use named credentials with a custom Authorization header that uses Basic authentication. For more on how to create external credentials with custom headers, see Create or Edit an External Credential.

          1. Create an external credential. Give it a name such as BasicAuth.
          2. Set the credential’s authentication protocol to Custom. Save the external credential.
          3. Scroll to Principals and click New.
            The new principal automatically has an identity type of Named Principal, which can’t be changed.
          4. Enter a Parameter Name, such as Admin or Marketing Group.
          5. Optionally, enter a sequence number.
          6. Under Authentication Parameters, click Add to add a parameter, for example Username. Set the value to the username you use for the web service provider. Click Add again to add another parameter, for instance Password, and set it as the password you use for the web service provider.
            Note
            Note Some systems don’t use passwords for Basic authentication. For example, when authenticating to GitHub, you use a personal access token instead of your user password.
            Authentication parameters for Basic authentication
          7. Save the principal.
          8. Now create a custom header with a formula for an encoded Basic username-password combination. See Create and Edit Custom Headers. On the external credential, scroll to Custom Headers and click New.
          9. Enter Authorization as the name of the custom header.
          10. For Value, enter:
            {!'Basic ' & BASE64ENCODE(BLOB($Credential.externalCredentialName.Username & ':' & $Credential.externalCredentialName.Password))}

            where externalCredentialName is the name of the external credential you created (’BasicAuth’ in this example).

            Base64 encoding is often used to convert binary data to a text string for easier transfer between systems. Binary data stored in some databases is sometimes referred to as a Binary Large OBject (BLOB). Two formulas, BLOB and BASE64ENCODE, used together, take the secret values, treat them as binary data, and then encode that binary data with base64. For more on formula functions like BASE64ENCODE, see Use Named Credential Formula Functions in Custom Headers.

          11. Set the sequence number as desired, or leave the default.
          12. Save the custom header.

          Use Basic Authentication with a Named Credential

          After you’ve created an external credential that uses custom headers with Basic authentication, link it to a named credential.

          These steps describe the general process of linking Basic authentication to a named credential. For full instructions on creating and editing named credentials, see Create or Edit a Named Credential.

          1. From Setup, in the Quick Find box, enter Named Credentials, and then select Named Credentials.
          2. Create a new named credential or select an existing one.
          3. Disable Generate Authorization Header in the named credential. Disabling this option ensures that the named credential uses the custom Authorization header that you created.
          4. In the named credential, be sure that Allow Formulas in HTTP Header is enabled.
          5. Enter the name of the external credential that uses Basic authentication.
          6. Save the named credential.

          A callout using this named credential returns successfully because it has the correct Authorization header. If the tokens expire or the URL changes, no changes to Apex code are needed. In addition to Apex, the credential can be used in no-code tools like External Services that provide integration with Flow.

           
          Loading
          Salesforce Help | Article