Quick Navigation
⚠️ READ FIRST: AGENT_EXECUTION_SPEC.md - Security contract and execution order
- Providers: Google | GitHub | LinkedIn | Apple | Twitter/X
- Patterns: OAuth Flow | Golden Path | Token Management | Refresh Token Lifecycle | Sessions | Data Models
- Adapters: Next.js | Express | Vanilla Node | Pseudocode | Laravel | Django | Flask | Rails | Vue
- Governance (mandatory): Env Contract | Error Handling | Account Linking | Testing
Mandatory Start (No Code)
- Produce a Discovery Report before any code or config changes.
- Read mandatory references:
references/AGENT_EXECUTION_SPEC.md and all governance references in references/governance/.
- Confirm provider(s), framework, language, deployment environment, and session strategy. If any are missing or ambiguous, stop and ask.
- Verify current provider documentation and security guidance (RFC 9700, RFC 7636, RFC 8252, OIDC Core) before implementation.
Multi-Part Implementation Note
OAuth/OIDC requires coordination between frontend and backend. This skill assumes full-stack access. If implementing in parts:
Scenario 1: Backend-only access
- Implement login start and callback routes.
- Document the route URLs for the frontend team.
- Provide success and error redirect URLs.
- See "Role Selection and Multi-Part Implementation" in
references/AGENT_EXECUTION_SPEC.md.
Scenario 2: Frontend-only access
- Implement a login button that calls an existing backend route.
- Do not implement OAuth flow logic client-side.
- Use the Frontend-Only Discovery Report in AGENT_EXECUTION_SPEC.md.
- If the backend uses cookie-based sessions, configure API calls with credentials included and derive auth state from the server.
- Do not modify existing auth logic unrelated to the social login being added.
Scenario 3: Full-stack access (recommended)
- Implement backend first (routes, handlers, validation).
- Then add frontend integration (button, redirects).
- Test end-to-end before deploying.
Discovery Report Requirements (Required First Output)
Include these items, even if the user did not ask:
- Detected framework and runtime (or ambiguity that blocks detection).
- Existing auth stack, session store, user model, and account linking rules.
- Current OAuth providers already integrated and any existing callback routes.
- Deployment constraints (domains, redirect URIs, environment variable system, secrets manager).
- Security middleware already present (CSRF, rate limiting, logging redaction).
If any required item is unknown and cannot be inferred from the repo, stop and ask.
Routing Logic
Provider routing:
- If provider is Google, read
references/providers/google.md.
- If provider is GitHub, read
references/providers/github.md.
- If provider is LinkedIn, read
references/providers/linkedin.md.
- If provider is Apple, read
references/providers/apple.md.
- If provider is Twitter/X, read
references/providers/twitter.md.
- If provider not supported, create a new provider file under
references/providers/ before proceeding.
- [All require CREDENTIALS.md first] Google | GitHub | LinkedIn | Apple | Twitter/X
Pattern routing:
- Always read
references/patterns/oauth-flow-core.md.
- If you need a canonical end-to-end example, read
references/patterns/golden-path.md.
- If tokens are stored, refreshed, or revoked, read
references/patterns/token-management.md.
- If refresh tokens are issued or rotated, read
references/patterns/refresh-token-lifecycle.md.
- If sessions or cookies are used, read
references/patterns/session-handling.md.
- If the project has existing authentication, read
references/patterns/existing-auth-integration.md.
- If cookies are used across different domains, read
references/patterns/samesite-decision-tree.md.
- If OIDC ID token validation is needed without heavy dependencies, read
references/patterns/jwks-validation-helper.md.
- If database changes are needed, read
references/patterns/data-models.md.
Adapter routing:
- If framework is Express, read
references/adapters/express-patterns.md.
- If framework is Next.js, read
references/adapters/nextjs-patterns.md.
- If framework is vanilla Node or custom server, read
references/adapters/vanilla-node-patterns.md.
- If framework is Laravel, read
references/adapters/laravel-patterns.md.
- If framework is Django, read
references/adapters/django-patterns.md.
- If framework is Flask, read
references/adapters/flask-patterns.md.
- If framework is Rails, read
references/adapters/rails-patterns.md.
- If framework is Vue, read
references/adapters/vue-patterns.md and select a backend adapter for server routes.
- If framework is unknown or not covered, read
references/adapters/pseudocode-patterns.md and create a new adapter file.
Governance routing (mandatory in every task):
references/governance/env-contract.md
references/governance/error-edge-cases.md
references/governance/account-linking.md
references/governance/testing-validation.md
Quick Architecture Router (Use After Discovery)
Once you've completed the Discovery Report and confirmed the provider, use this router to find relevant documentation quickly:
Backend Architecture:
- Separate API + frontend → Section 4.2 (JWT) or 4.3 (Sessions)
- Monolithic (Next.js, Rails, Django) → Section 4.3 + framework adapter
- Serverless → Section 4.4 (not yet implemented, use pseudocode patterns)
Provider Documentation:
- Confirmed provider →
references/providers/{provider}/CREDENTIALS.md then references/providers/{provider}.md
- Multiple providers → Read multi-provider patterns first
Account Linking:
- Have
auth_identities table → Section 5.1
- Only
users table → Section 5.2
This router does NOT replace discovery. Always complete the Discovery Report first.
Forbidden Practices (Explicitly Prohibited)
- Implicit flow or token response in front-channel redirects.
- Skipping
state or nonce validation.
- Wildcard or open redirect URI matching.
- Storing access, refresh, or ID tokens in localStorage or client-side cookies.
- Logging auth codes, tokens, client secrets, or full provider responses.
- Using unverified email claims as proof of identity.
- Reusing sessions across login (no session rotation).
- Committing
.env files or hardcoding secrets in logic.
- Using the
sub (subject) claim as a display name (it is an ID, not a name).
Stop Conditions (Must Ask Clarifying Questions)
Stop and ask before any implementation if any of these are missing:
- Provider client credentials and allowed redirect URIs.
- The app framework and runtime are ambiguous or conflicting.
- Session strategy is unclear (cookie vs server session store).
- Account linking rules are unknown (merge by email or provider id).
- The environment variable system or secrets manager is not defined.
- Secrets Rotation Strategy is undefined (e.g., how to handle old vs new client secrets during a key roll).
Required Output Structure (Required)
See references/AGENT_EXECUTION_SPEC.md for the required output structure (source of truth). Summary:
- Discovery Report
- Provider Docs Verification
- Required Environment Variables
- Planned File Changes
- Security Checklist Compliance
- Implementation Plan
- Testing Checklist
In Required Environment Variables, always separate backend/server-only vs frontend/public and state who must provide them.
If you cannot comply with the required order, stop and ask for clarification.
Multi-Provider Invariant
Assume multiple providers will coexist. Design routes, database models, and session logic so adding a second provider does not break the first.
Documentation Freshness
Provider files are guidance only. You must verify the latest provider docs before coding. If docs conflict, stop and ask.
Converted and distributed by TomeVault — claim your Tome and manage your conversions.
1---2name: social-auth3description: Security control system for OAuth 2.0 and OpenID Connect social login. Enforces discovery, strict security invariants, and deterministic outputs before any code is written. Covers OAuth login, provider integration, auth code plus PKCE flow, token and session handling, account linking, multi provider auth, and framework adapters (Next.js, Express, Node). Triggers on login flows, callbacks, token exchange, refresh, cookies, and adapter setup. Use when this capability is needed.4---56## Quick Navigation78**⚠️ READ FIRST**: [AGENT_EXECUTION_SPEC.md](references/AGENT_EXECUTION_SPEC.md) - Security contract and execution order910- **Providers**: Google | GitHub | LinkedIn | Apple | Twitter/X11- **Patterns**: OAuth Flow | Golden Path | Token Management | Refresh Token Lifecycle | Sessions | Data Models 12- **Adapters**: Next.js | Express | Vanilla Node | Pseudocode | Laravel | Django | Flask | Rails | Vue13- **Governance** (mandatory): Env Contract | Error Handling | Account Linking | Testing141516## Mandatory Start (No Code)17181. Produce a Discovery Report before any code or config changes.192. Read mandatory references: `references/AGENT_EXECUTION_SPEC.md` and all governance references in `references/governance/`.203. Confirm provider(s), framework, language, deployment environment, and session strategy. If any are missing or ambiguous, stop and ask.214. Verify current provider documentation and security guidance (RFC 9700, RFC 7636, RFC 8252, OIDC Core) before implementation.2223## Multi-Part Implementation Note2425OAuth/OIDC requires coordination between frontend and backend. This skill assumes full-stack access. If implementing in parts:2627Scenario 1: Backend-only access28- Implement login start and callback routes.29- Document the route URLs for the frontend team.30- Provide success and error redirect URLs.31- See "Role Selection and Multi-Part Implementation" in `references/AGENT_EXECUTION_SPEC.md`.3233Scenario 2: Frontend-only access34- Implement a login button that calls an existing backend route.35- Do not implement OAuth flow logic client-side.36- Use the Frontend-Only Discovery Report in AGENT_EXECUTION_SPEC.md.37- If the backend uses cookie-based sessions, configure API calls with credentials included and derive auth state from the server.38- Do not modify existing auth logic unrelated to the social login being added.3940Scenario 3: Full-stack access (recommended)41- Implement backend first (routes, handlers, validation).42- Then add frontend integration (button, redirects).43- Test end-to-end before deploying.4445## Discovery Report Requirements (Required First Output)4647Include these items, even if the user did not ask:48- Detected framework and runtime (or ambiguity that blocks detection).49- Existing auth stack, session store, user model, and account linking rules.50- Current OAuth providers already integrated and any existing callback routes.51- Deployment constraints (domains, redirect URIs, environment variable system, secrets manager).52- Security middleware already present (CSRF, rate limiting, logging redaction).5354If any required item is unknown and cannot be inferred from the repo, stop and ask.555657## Routing Logic5859Provider routing:60- If provider is Google, read `references/providers/google.md`.61- If provider is GitHub, read `references/providers/github.md`.62- If provider is LinkedIn, read `references/providers/linkedin.md`.63- If provider is Apple, read `references/providers/apple.md`.64- If provider is Twitter/X, read `references/providers/twitter.md`.65- If provider not supported, create a new provider file under `references/providers/` before proceeding.66- [All require CREDENTIALS.md first] Google | GitHub | LinkedIn | Apple | Twitter/X6768Pattern routing:69- Always read `references/patterns/oauth-flow-core.md`.70- If you need a canonical end-to-end example, read `references/patterns/golden-path.md`.71- If tokens are stored, refreshed, or revoked, read `references/patterns/token-management.md`.72- If refresh tokens are issued or rotated, read `references/patterns/refresh-token-lifecycle.md`.73- If sessions or cookies are used, read `references/patterns/session-handling.md`.74- If the project has existing authentication, read `references/patterns/existing-auth-integration.md`.75- If cookies are used across different domains, read `references/patterns/samesite-decision-tree.md`.76- If OIDC ID token validation is needed without heavy dependencies, read `references/patterns/jwks-validation-helper.md`.77- If database changes are needed, read `references/patterns/data-models.md`.7879Adapter routing:80- If framework is Express, read `references/adapters/express-patterns.md`.81- If framework is Next.js, read `references/adapters/nextjs-patterns.md`.82- If framework is vanilla Node or custom server, read `references/adapters/vanilla-node-patterns.md`.83- If framework is Laravel, read `references/adapters/laravel-patterns.md`.84- If framework is Django, read `references/adapters/django-patterns.md`.85- If framework is Flask, read `references/adapters/flask-patterns.md`.86- If framework is Rails, read `references/adapters/rails-patterns.md`.87- If framework is Vue, read `references/adapters/vue-patterns.md` and select a backend adapter for server routes.88- If framework is unknown or not covered, read `references/adapters/pseudocode-patterns.md` and create a new adapter file.8990Governance routing (mandatory in every task):91- `references/governance/env-contract.md`92- `references/governance/error-edge-cases.md`93- `references/governance/account-linking.md`94- `references/governance/testing-validation.md`959697## Quick Architecture Router (Use After Discovery)9899Once you've completed the Discovery Report and confirmed the provider, use this router to find relevant documentation quickly:100101**Backend Architecture**:102- Separate API + frontend → Section 4.2 (JWT) or 4.3 (Sessions)103- Monolithic (Next.js, Rails, Django) → Section 4.3 + framework adapter104- Serverless → Section 4.4 (not yet implemented, use pseudocode patterns)105106**Provider Documentation**:107- Confirmed provider → `references/providers/{provider}/CREDENTIALS.md` then `references/providers/{provider}.md`108- Multiple providers → Read multi-provider patterns first109110**Account Linking**:111- Have `auth_identities` table → Section 5.1112- Only `users` table → Section 5.2113114This router does NOT replace discovery. Always complete the Discovery Report first.115116117118## Forbidden Practices (Explicitly Prohibited)119120- Implicit flow or token response in front-channel redirects.121- Skipping `state` or `nonce` validation.122- Wildcard or open redirect URI matching.123- Storing access, refresh, or ID tokens in localStorage or client-side cookies.124- Logging auth codes, tokens, client secrets, or full provider responses.125- Using unverified email claims as proof of identity.126- Reusing sessions across login (no session rotation).127- Committing `.env` files or hardcoding secrets in logic.128- Using the `sub` (subject) claim as a display name (it is an ID, not a name).129130## Stop Conditions (Must Ask Clarifying Questions)131132Stop and ask before any implementation if any of these are missing:133- Provider client credentials and allowed redirect URIs.134- The app framework and runtime are ambiguous or conflicting.135- Session strategy is unclear (cookie vs server session store).136- Account linking rules are unknown (merge by email or provider id).137- The environment variable system or secrets manager is not defined.138- Secrets Rotation Strategy is undefined (e.g., how to handle old vs new client secrets during a key roll).139140## Required Output Structure (Required)141142See `references/AGENT_EXECUTION_SPEC.md` for the required output structure (source of truth). Summary:1431. Discovery Report1442. Provider Docs Verification1453. Required Environment Variables1464. Planned File Changes1475. Security Checklist Compliance1486. Implementation Plan1497. Testing Checklist150151In Required Environment Variables, always separate backend/server-only vs frontend/public and state who must provide them.152153If you cannot comply with the required order, stop and ask for clarification.154155## Multi-Provider Invariant156157Assume multiple providers will coexist. Design routes, database models, and session logic so adding a second provider does not break the first.158159## Documentation Freshness160161Provider files are guidance only. You must verify the latest provider docs before coding. If docs conflict, stop and ask.162163---164> Converted and distributed by [TomeVault](https://tomevault.io/claim/babatunde-fatai) — claim your Tome and manage your conversions.165<!-- tomevault:4.0:skill_md:2026-04-11 -->