afv-library/skills/integration-connectivity-generate/assets/named-credentials/custom-auth.namedCredential-meta.xml

72 lines
2.2 KiB
XML
Raw Normal View History

<?xml version="1.0" encoding="UTF-8"?>
<!--
Named Credential Template: Custom Authentication (API Key / Basic Auth)
Use Case: Simple APIs with API key or username/password
- Internal APIs
- Legacy systems
- APIs with simple authentication
- Development/testing environments
Authentication Types:
- Basic Auth: Username + Password in Authorization header
- API Key: Custom header with API key value
Setup Steps:
1. Replace all {{placeholder}} values
2. Deploy to org
3. Enter credentials via Setup → Named Credentials UI
File Location: force-app/main/default/namedCredentials/{{CredentialName}}.namedCredential-meta.xml
-->
<NamedCredential xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>{{CredentialName}}</fullName>
<label>{{CredentialLabel}}</label>
<!-- Base URL for the external service -->
<endpoint>{{BaseEndpoint}}</endpoint>
<!--
Authentication Configuration
For Basic Auth:
- principalType: NamedUser
- protocol: Password
- generateAuthorizationHeader: true
For API Key (via custom header):
- principalType: Anonymous
- protocol: NoAuthentication
- Use calloutOptions or Apex to add header
-->
<principalType>NamedUser</principalType>
<protocol>Password</protocol>
<!--
Username for Basic Auth
Password is entered via UI after deployment (NOT stored in metadata)
-->
<username>{{Username}}</username>
<!-- Request Options -->
<generateAuthorizationHeader>true</generateAuthorizationHeader>
<allowMergeFieldsInBody>true</allowMergeFieldsInBody>
<allowMergeFieldsInHeader>true</allowMergeFieldsInHeader>
<!--
SECURITY WARNING:
- Password is stored securely by Salesforce, NOT in this file
- After deployment, configure password via:
Setup → Named Credentials → Edit → Enter Password
- Never commit passwords to source control
For API Key pattern (in Apex):
HttpRequest req = new HttpRequest();
req.setEndpoint('callout:{{CredentialName}}/endpoint');
req.setHeader('X-API-Key', '{!$Credential.Password}');
Or use External Credentials (API 61+) with Custom headers for cleaner API key handling.
-->
</NamedCredential>