协作头脑风暴
brainstorming
在实现前澄清需求、探索设计选择,并形成清晰的开发方向。
auth-system-setup【开发与工程】When the user wants to set up authentication and authorization for a web application. Use when the user mentions "auth," "login," "OAuth," "SSO," "single sign-on," "role-based access," "RBAC," "permissions," "user roles," "access control," "authentication," or "authorization." Covers OAuth 2.0 provider integration, session management, and role/permis…
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
Designs and implements complete authentication and authorization systems for web applications. Covers OAuth 2.0 provider integration (Google, GitHub, Microsoft), session and token management, role-based access control (RBAC), and permission architectures. Generates production-ready code, database migrations, and tests.
Before generating any code, determine:
Create the auth flow diagram and data model:
For each OAuth provider:
Always use PKCE for public clients. Always validate the state parameter.
Generate the permission-checking middleware:
authorize(resource, action) → middleware function
1. Extract user from request (via JWT or session)
2. Load user roles and permissions (cache with TTL)
3. Check if any role grants the required permission
4. Return 403 with clear error if denied
For row-level security, add ownership filters:
filterByOwnership(resource) → middleware function
1. If user role has wildcard access, skip filter
2. Otherwise, add WHERE clause: resource.owner_id = user.id
3. Apply to SELECT, UPDATE, DELETE queries
Create tests for:
Prompt: "Set up Google OAuth with JWT tokens for my Express app. I need admin and user roles."
Output:
auth/providers/google.ts — OAuth 2.0 + PKCE flowauth/middleware/authenticate.ts — JWT verificationauth/middleware/authorize.ts — Role checkermigrations/001_auth_tables.sql — Users, roles, permissions, refresh_tokensauth/services/token.service.ts — JWT issuance with refresh rotationauth/routes.ts — /auth/google, /auth/callback, /auth/refresh, /auth/logouttests/auth.test.ts — 18 integration testsPrompt: "Add GitHub login to my Django app. Each organization has its own roles: owner, editor, viewer."
Output:
accounts/providers/github.py — OAuth integration via django-allauthaccounts/models.py — Organization, Membership, Role modelsaccounts/permissions.py — Per-organization permission backendaccounts/middleware.py — Org context middleware (from subdomain or header)accounts/decorators.py — @require_org_role('editor') decoratormigrations/0001_multi_tenant_auth.py — Schema migrationtests/test_permissions.py — 22 test cases across org boundaries