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/user-agent-social-sign-on.md
View on GitHub# User-Agent with Social Sign-On Flow Template
OAuth 2.0 User-Agent flow combined with Social Sign-On (OIDC), where Salesforce acts as both the Authorization Provider (for the client) and the Relying Party (to the external OIDC Provider like Facebook, Google, etc.).
## When to Use
- Mobile apps or SPAs requiring social login (Google, Facebook, etc.)
- When Salesforce is an intermediary between your app and social identity providers
- User-Agent flow (implicit-like) with external OIDC authentication
- Silent re-authentication scenarios (OP session cookies)
## 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(165,243,252,0.3) CLIENT
participant C as š± Client<br/>(Mobile App)
end
box rgba(221,214,254,0.3) SALESFORCE
participant SF as āļø Salesforce<br/>(Auth Provider /<br/>Relying Party)
end
box rgba(254,215,170,0.3) OIDC PROVIDER
participant OP as š OIDC Provider<br/>(Google/Facebook)
end
Note over C,OP: User-Agent Flow with Social Sign-On (OIDC)
%% Phase 1: Initial Access Token Request
C->>SF: š¤ Access Token Request
Note over C,SF: GET /services/oauth2/authorize<br/>client_id, response_type=token<br/>redirect_uri, state, scope
SF->>SF: āļø Check for RP session
%% Phase 2: Redirect to OIDC Provider
SF->>C: š„ HTTP Redirect to OP
Note over SF,C: Redirect to OIDC authorize endpoint
C->>OP: š¤ Auth Code Request
Note over C,OP: GET /authorize<br/>response_type=code<br/>redirect_uri=/services/authglobalcallback<br/>scope, state
%% Phase 3: Authentication at OP
OP->>OP: āļø Check for OP session
OP->>C: š„ Display Login Page
C->>OP: š User authenticates
OP->>OP: āļø Validate credentials
OP->>C: š„ Display Consent Screen (first time only)
C->>OP: š User grants consent
OP->>OP: āļø Generate authorization code
%% Phase 4: Return to Salesforce
OP->>C: š„ HTTP Redirect to Salesforce
Note over OP,C: Redirect to /services/authglobalcallback<br/>?code=OP_AUTH_CODE&state=...
C->>SF: š¤ Deliver OP Auth Code
Note over C,SF: GET /services/authglobalcallback<br/>code=OP_AUTH_CODE, state
%% Phase 5: Salesforce exchanges code with OP
SF->>OP: š¤ Access Token Request
Note over SF,OP: POST to OP Token Endpoint<br/>client_id, client_secret<br/>code, redirect_uri, state
OP->>OP: āļø Validate client & code
OP-->>SF: š„ Access Token Response
Note over OP,SF: id_token (JWT)<br/>access_token<br/>refresh_token
SF->>SF: š Verify ID token signature
%% Phase 6: Optional UserInfo
rect rgba(248,250,252,0.5)
Note over SF,OP: Optional: UserInfo Endpoint
SF->>OP: š¤ Request User Information
Note over SF,OP: POST /userinfo<br/>Authorization: Bearer ACCESS_TOKEN
OP-->>SF: š„ User Info Response
Note over OP,SF: User claims (email, name, etc.)
SF->>SF: š Validate sub matches ID token
end
%% Phase 7: Salesforce User Provisioning
SF->>SF: āļø Invoke registration handler<br/>to create/update user
%% Phase 8: User Authorization for Salesforce
SF->>C: š„ Display Salesforce Consent
Note over SF,C: "App requests:<br/>⢠API Access<br/>⢠Refresh Token"
C->>SF: š User grants Salesforce consent
%% Phase 9: Return tokens to Client
SF->>C: š„ Redirect to Client Callback
Note over SF,C: Redirect URI with:<br/>access_token (Salesforce)<br/>refresh_token<br/>instance_url
C->>C: āļø Store Salesforce tokens
%% Phase 10: API Usage
C->>SF: š¤ Use Salesforce APIs
Note over C,SF: Authorization: Bearer SF_ACCESS_TOKEN
SF-->>C: ā
API Response
Note over C,SF: ā ļø OP session cookie enables<br/>silent re-auth (~15 min)
```
## ASCII Fallback Template
```text
āāāāāāāāāāāāāāāāāā āāāāāāāāāāāāāāāāāāāāāā āāāāāāāāāāāāāāāāāāāāāāā
ā Client ā ā Salesforce ā ā OIDC Provider ā
ā (Mobile App) ā ā (Auth/RP Server) ā ā (Google/Facebook) ā
āāāāāāāāā¬āāāāāāāāā āāāāāāāāāāā¬āāāāāāāāāāā āāāāāāāāāāāā¬āāāāāāāāāāā
ā ā ā
ā 1. Access Token Req ā ā
ā (response_type= ā ā
ā token) ā ā
āāāāāāāāāāāāāāāāāāāāāāāā>ā ā
ā ā ā
ā 2. Redirect to OP ā ā
ā<āāāāāāāāāāāāāāāāāāāāāāāā ā
ā ā ā
ā 3. Auth Code Request (response_type=code) ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā>ā
ā ā ā
ā 4. Login Page ā
ā<āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā ā ā
ā 5. Enter Credentials (authenticate) ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā>ā
ā ā ā
ā 6. Consent Screen (first time) ā
ā<āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā ā ā
ā 7. Grant Consent ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā>ā
ā ā ā
ā 8. Redirect with ?code=OP_AUTH_CODE ā
ā<āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā ā ā
ā 9. Deliver OP Code ā ā
āāāāāāāāāāāāāāāāāāāāāāāā>ā ā
ā ā ā
ā ā 10. POST Token Request ā
ā ā (code, secret) ā
ā āāāāāāāāāāāāāāāāāāāāāāāāāāā>ā
ā ā ā
ā ā 11. ID Token + Access ā
ā ā Token Response ā
ā ā<āāāāāāāāāāāāāāāāāāāāāāāāāāā
ā ā ā
ā ā [Optional: UserInfo] ā
ā ā 12. GET /userinfo ā
ā āāāāāāāāāāāāāāāāāāāāāāāāāāā>ā
ā ā ā
ā ā 13. User Claims ā
ā ā<āāāāāāāāāāāāāāāāāāāāāāāāāāā
ā ā ā
ā ā 14. Registration Handler ā
ā ā (create/update user) ā
ā āāāāāāāāāāāāāāā ā
ā ā ā ā
ā ā<āāāāāāāāāāāāā ā
ā ā ā
ā 15. SF Consent Screen ā ā
ā<āāāāāāāāāāāāāāāāāāāāāāāā ā
ā ā ā
ā 16. Grant SF Consent ā ā
āāāāāāāāāāāāāāāāāāāāāāāā>ā ā
ā ā ā
ā 17. Redirect with ā ā
ā SF Access Token ā ā
ā + Refresh Token ā ā
ā<āāāāāāāāāāāāāāāāāāāāāāāā ā
ā ā ā
ā 18. Call SF APIs ā ā
āāāāāāāāāāāāāāāāāāāāāāāā>ā ā
ā ā ā
ā 19. API Response ā
ā ā
ā<āāāāāāāāāāāāāāāāāāāāāāāā ā
```
## Key Concepts
### Dual Role of Salesforce
| Role | Context | Responsibility |
|------|---------|----------------|
| **Authorization Provider** | OAuth flow with Client | Issues access tokens to your app |
| **Relying Party (RP)** | OIDC flow with Social Provider | Consumes ID tokens from Google/Facebook |
### Authentication Endpoints
| System | Endpoint | Purpose |
|--------|----------|---------|
| Salesforce Auth | `/services/oauth2/authorize` | Start User-Agent flow |
| Salesforce Callback | `/services/authglobalcallback` | Receive OP auth code |
| Salesforce Token | `/services/oauth2/token` | (Not used in User-Agent) |
| OP Authorization | Provider-specific | `/authorize` endpoint |
| OP Token | Provider-specific | Exchange code for tokens |
| OP UserInfo | Provider-specific | Get user profile claims |
## Security Considerations
1. **OP Session Cookies** - Enable silent re-authentication (~15 min intervals)
2. **ID Token Validation** - Salesforce verifies JWT signature from OP
3. **Sub Claim Matching** - UserInfo `sub` must match ID token `sub`
4. **State Parameter** - CSRF protection between all parties
5. **Registration Handler** - Custom Apex to map OP user to Salesforce User
## Salesforce Configuration
### Auth. Provider Setup
```text
Setup ā Auth. Providers ā New
āāā Provider Type: OpenID Connect (or specific: Google, Facebook)
āāā Consumer Key: [From OP Developer Console]
āāā Consumer Secret: [From OP Developer Console]
āāā Authorize Endpoint: https://provider.com/authorize
āāā Token Endpoint: https://provider.com/token
āāā User Info Endpoint: https://provider.com/userinfo (optional)
āāā Registration Handler: [Your Apex Class]
```
### Registration Handler Example
```apex
public class SocialLoginHandler implements Auth.RegistrationHandler {
public User createUser(Id portalId, Auth.UserData data) {
// Map social identity to Salesforce User
User u = new User();
u.Username = data.email + '.social';
u.Email = data.email;
u.FirstName = data.firstName;
u.LastName = data.lastName;
// ... additional mapping
return u;
}
public void updateUser(Id userId, Id portalId, Auth.UserData data) {
// Update existing user on subsequent logins
User u = [SELECT Id FROM User WHERE Id = :userId];
u.Email = data.email;
update u;
}
}
```
## Token Types
| Token | Issued By | Purpose |
|-------|-----------|---------|
| OP Auth Code | OIDC Provider | Short-lived, exchanged by SF |
| OP ID Token | OIDC Provider | JWT with user identity claims |
| OP Access Token | OIDC Provider | Used by SF to call OP UserInfo |
| SF Access Token | Salesforce | Used by Client to call SF APIs |
| SF Refresh Token | Salesforce | Long-lived, refresh SF access |
## Customization Points
Replace these placeholders:
- `CLIENT_ID` ā Your Connected App's Consumer Key
- `CALLBACK_URL` ā Your registered callback URL
- `OP_CLIENT_ID` ā Consumer Key from Social Provider
- `OP_CLIENT_SECRET` ā Consumer Secret from Social Provider
## Reference
- [Salesforce Identity: User-Agent with Social Sign-On](https://cloudsundial.com/salesforce-identity/user-agent-with-social-sign-on)
- [OpenID Connect Core 1.0](https://openid.net/specs/openid-connect-core-1_0.html)
- [Salesforce Auth. Providers Documentation](https://help.salesforce.com/s/articleView?id=sf.sso_provider_openidconnect.htm)
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 | Verified | 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: 323k | 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: 323k | 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: 323k | Updated | Claude CodeCodex | Verified | Install |