forcedotcom/sf-skills / skills/external-diagram-mermaid-generate
external-diagram-mermaid-generate
UnverifiedSalesforce architecture diagrams using Mermaid with ASCII fallback. Use this skill when generating text-based diagrams for Salesforce architecture, OAuth flows, ERDs, integration sequences, or Agentforce structure. TRIGGER when: user says "diagram", "visualize", "ERD", or asks for sequence diagrams, flowcharts, class diagrams, or architecture visualizations in Mermaid. DO NOT TRIGGER when: user asks about non-Salesforce systems.
assets/oauth/client-credentials.md
View on GitHub# Client Credentials Flow Template
OAuth 2.0 Client Credentials Grant for server-to-server authentication using client_id and client_secret.
## When to Use
- Service accounts
- Background processes
- System-to-system integrations
- When no specific user context is needed
- External Client Apps (ECAs) with client credentials enabled
## Prerequisites
1. Connected App or External Client App configured
2. Client Credentials flow enabled
3. Execution user assigned via Permission Set (for ECAs)
## Mermaid Template
```mermaid
%%{init: {'theme': 'base', 'themeVariables': {
'actorBkg': '#ddd6fe',
'actorTextColor': '#1f2937',
'actorBorder': '#6d28d9',
'signalColor': '#334155',
'signalTextColor': '#1f2937',
'noteBkgColor': '#f8fafc',
'noteTextColor': '#1f2937',
'noteBorderColor': '#334155'
}}}%%
sequenceDiagram
autonumber
box rgba(221,214,254,0.3) CLIENT APPLICATION
participant C as š„ļø Service<br/>(Backend Server)
end
box rgba(167,243,208,0.3) SALESFORCE
participant SF as āļø Salesforce<br/>Authorization Server
end
Note over C,SF: Client Credentials Flow (RFC 6749 Section 4.4)
C->>C: 1. Retrieve Client Credentials
Note over C: client_id = CONSUMER_KEY<br/>client_secret = CONSUMER_SECRET
C->>SF: 2. POST /services/oauth2/token
Note over C,SF: grant_type=client_credentials<br/>client_id=CONSUMER_KEY<br/>client_secret=CONSUMER_SECRET
SF->>SF: 3. Validate Client Credentials
Note over SF: Verify client_id exists<br/>Verify client_secret matches
SF->>SF: 4. Determine Execution User
Note over SF: For ECA: Use assigned<br/>Permission Set user<br/><br/>For Connected App: Use<br/>"Run As" user
SF->>SF: 5. Generate Access Token
Note over SF: Token runs in context<br/>of execution user
SF->>C: 6. Return Access Token
Note over SF,C: {<br/> "access_token": "...",<br/> "instance_url": "https://...",<br/> "token_type": "Bearer",<br/> "issued_at": "..."<br/>}
Note over C: ā ļø No refresh_token returned<br/>ā ļø No user context (runs as service user)
C->>SF: 7. Make API Calls
Note over C,SF: Authorization: Bearer ACCESS_TOKEN
SF->>SF: 8. Execute as Service User
Note over SF: All operations run with<br/>execution user's permissions
SF->>C: 9. API Response
```
## ASCII Fallback Template
```text
āāāāāāāāāāāāāāāāāāāāāāāāā āāāāāāāāāāāāāāāāāāāāāā
ā Service/Backend ā ā Salesforce ā
ā (client_id/secret) ā ā (Auth Server) ā
āāāāāāāāāāāāā¬āāāāāāāāāāāā āāāāāāāāāāā¬āāāāāāāāāāā
ā ā
ā 1. POST /token ā
ā grant_type= ā
ā client_credentials ā
ā client_id=KEY ā
ā client_secret=SECRET ā
āāāāāāāāāāāāāāāāāāāāāāāāāāā>ā
ā ā
ā 2. Validate ā
ā credentials ā
ā ā
ā 3. Determine ā
ā execution ā
ā user ā
ā ā
ā 4. Generate ā
ā access token ā
ā ā
ā 5. Access Token ā
ā (NO refresh token!) ā
ā (NO user context!) ā
ā<āāāāāāāāāāāāāāāāāāāāāāāāāāā
ā ā
ā 6. API Request ā
ā (Bearer token) ā
āāāāāāāāāāāāāāāāāāāāāāāāāāā>ā
ā ā
ā 7. API Response ā
ā (runs as svc user) ā
ā<āāāāāāāāāāāāāāāāāāāāāāāāāāā
```
## Token Request
```bash
curl -X POST https://login.salesforce.com/services/oauth2/token \
-d "grant_type=client_credentials" \
-d "client_id=YOUR_CONSUMER_KEY" \
-d "client_secret=YOUR_CONSUMER_SECRET"
```
## Response Example
```json
{
"access_token": "00D5g000001ABC...!ARcAQNlBrLGj...",
"instance_url": "https://mycompany.my.salesforce.com",
"token_type": "Bearer",
"issued_at": "1702123456789"
}
```
## Code Examples
### Python
```python
import requests
response = requests.post(
'https://login.salesforce.com/services/oauth2/token',
data={
'grant_type': 'client_credentials',
'client_id': 'YOUR_CONSUMER_KEY',
'client_secret': 'YOUR_CONSUMER_SECRET'
}
)
token_data = response.json()
access_token = token_data['access_token']
instance_url = token_data['instance_url']
# Make API call
headers = {'Authorization': f'Bearer {access_token}'}
api_response = requests.get(
f'{instance_url}/services/data/v66.0/sobjects/Account',
headers=headers
)
```
### Node.js
```javascript
const axios = require('axios');
const response = await axios.post(
'https://login.salesforce.com/services/oauth2/token',
new URLSearchParams({
grant_type: 'client_credentials',
client_id: 'YOUR_CONSUMER_KEY',
client_secret: 'YOUR_CONSUMER_SECRET'
})
);
const { access_token, instance_url } = response.data;
// Make API call
const apiResponse = await axios.get(
`${instance_url}/services/data/v66.0/sobjects/Account`,
{ headers: { Authorization: `Bearer ${access_token}` } }
);
```
## Connected App vs External Client App
| Feature | Connected App | External Client App (ECA) |
|---------|--------------|--------------------------|
| Secret Management | Manual rotation | Automatic rotation supported |
| User Assignment | "Run As" user | Permission Set assignment |
| Configuration | Setup ā App Manager | Setup ā External Client Apps |
| Recommended | Legacy integrations | New integrations (2024+) |
## Key Characteristics
| Aspect | Value |
|--------|-------|
| User Interaction | None required |
| Refresh Token | **Not returned** - re-authenticate |
| User Context | Runs as execution/service user |
| Scopes | Limited to service account permissions |
| Best For | System integrations, batch jobs |
## Enabling Client Credentials
### For Connected App
1. Setup ā App Manager ā Edit Connected App
2. Enable OAuth Settings
3. Enable "Client Credentials Flow"
4. Set "Run As" user
### For External Client App
1. Setup ā External Client Apps ā New
2. Configure OAuth Settings
3. Enable `isClientCredentialsEnabled`
4. Assign Permission Set with user
## Security Considerations
1. **Protect client_secret** - Never expose in client-side code
2. **Use dedicated service user** with minimal permissions
3. **Rotate secrets regularly** (especially for Connected Apps)
4. **Monitor API usage** - Set up event monitoring
5. **Restrict IP ranges** if possible
## Limitations
- No refresh tokens (must re-authenticate)
- No user context (cannot impersonate users)
- Limited to service user's permissions
- Cannot use for user-specific operations
## Customization Points
Replace these placeholders:
- `CONSUMER_KEY` ā Your Connected App's Consumer Key
- `CONSUMER_SECRET` ā Your Connected App's Consumer Secret
- `login.salesforce.com` ā Or `test.salesforce.com` for sandbox
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis. | Stars: 472k | Updated | Claude CodeCodex | Unverified | Install |
| diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why ā repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" ā or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness. | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependencies | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself ā your human partner chose inline execution, or no subagent tool is available | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |