auth-implementation-patterns
它能做什么
这个工具可以帮你理解并实现安全的身份验证(确认用户是谁)和权限控制(确认用户能做什么)。它涵盖密码登录、社交账号登录以及基于用户组的访问控制等方法。
适用场景
- ✓当你为网站或应用创建登录系统时。
- ✓当你需要保护数据或功能的访问权限时。
- ✓当你想弄清楚为什么某个用户无法访问某些内容时。
技能链接
https://github.com/wshobson/agents/blob/main/plugins/developer-essentials/skills/auth-implementation-patterns/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“怎样才能让只有管理员可以查看某些报表?”
每周 5 个新技能,1 分钟读完。
工作原理
它会讲解身份验证(你是谁)和授权(你能做什么)等概念,介绍使用令牌(JWT)或会话(session)管理访问权限的方法,并提供安全建议。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Authentication & Authorization Implementation Patterns
Build secure, scalable authentication and authorization systems using industry-standard patterns and modern best practices.
When to Use This Skill
- Implementing user authentication systems
- Securing REST or GraphQL APIs
- Adding OAuth2/social login
- Implementing role-based access control (RBAC)
- Designing session management
- Migrating authentication systems
- Debugging auth issues
- Implementing SSO or multi-tenancy
Core Concepts
1. Authentication vs Authorization
Authentication (AuthN): Who are you?
- Verifying identity (username/password, OAuth, biometrics)
- Issuing credentials (sessions, tokens)
- Managing login/logout
Authorization (AuthZ): What can you do?
- Permission checking
- Role-based access control (RBAC)
- Resource ownership validation
- Policy enforcement
2. Authentication Strategies
Session-Based:
- Server stores session state
- Session ID in cookie
- Traditional, simple, stateful
Token-Based (JWT):
- Stateless, self-contained
- Scales horizontally
- Can store claims
OAuth2/OpenID Connect:
- Delegate authentication
- Social login (Google, GitHub)
- Enterprise SSO
Detailed patterns and worked examples
Detailed pattern documentation lives in references/details.md. Read that file when the navigation tier above is insufficient.
Best Practices
- Never Store Plain Passwords: Always hash with bcrypt/argon2
- Use HTTPS: Encrypt data in transit
- Short-Lived Access Tokens: 15-30 minutes max
- Secure Cookies: httpOnly, secure, sameSite flags
- Validate All Input: Email format, password strength
- Rate Limit Auth Endpoints: Prevent brute force attacks
- Implement CSRF Protection: For session-based auth
- Rotate Secrets Regularly: JWT secrets, session secrets
- Log Security Events: Login attempts, failed auth
- Use MFA When Possible: Extra security layer
Common Pitfalls
- Weak Passwords: Enforce strong password policies
- JWT in localStorage: Vulnerable to XSS, use httpOnly cookies
- No Token Expiration: Tokens should expire
- Client-Side Auth Checks Only: Always validate server-side
- Insecure Password Reset: Use secure tokens with expiration
- No Rate Limiting: Vulnerable to brute force
- Trusting Client Data: Always validate on server
常见问题
身份验证和授权有什么区别?
身份验证是证明你是谁,例如输入用户名和密码。授权则是在证明身份之后,决定你被允许做什么,例如查看或编辑某些内容。
什么是 JWT?
JWT(JSON Web Token)是一种在各方之间安全传递信息的方式。用户登录后会拿到一个类似“通行证”的令牌,系统凭它就能识别用户,而无需每次都去查询数据库。
为什么不能以明文形式存储密码?
以明文存储密码非常危险。一旦系统被入侵,攻击者就能获取所有用户的密码。因此密码需要经过“打乱”处理(即哈希),使其无法被直接读取。
详情
作者的原始描述
Master authentication and authorization patterns including JWT, OAuth2, session management, and RBAC to build secure, scalable access control systems. Use when implementing auth systems, securing APIs, or debugging security issues.
repo: wshobson/agents
热度
- GitHub 星标
- 41k
- 排名
- #6674
- 许可证
- MIT
- 更新时间
- 2026/10/15
评论
- …