跳到正文
Skillpedia
安全41k · #6674

auth-implementation-patterns

它能做什么

这个工具可以帮你理解并实现安全的身份验证(确认用户是谁)和权限控制(确认用户能做什么)。它涵盖密码登录、社交账号登录以及基于用户组的访问控制等方法。

适用场景

  • ✓当你为网站或应用创建登录系统时。
  • ✓当你需要保护数据或功能的访问权限时。
  • ✓当你想弄清楚为什么某个用户无法访问某些内容时。

技能链接

https://github.com/wshobson/agents/blob/main/plugins/developer-essentials/skills/auth-implementation-patterns/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/wshobson/agents/blob/main/plugins/developer-essentials/skills/auth-implementation-patterns/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 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

  1. Never Store Plain Passwords: Always hash with bcrypt/argon2
  2. Use HTTPS: Encrypt data in transit
  3. Short-Lived Access Tokens: 15-30 minutes max
  4. Secure Cookies: httpOnly, secure, sameSite flags
  5. Validate All Input: Email format, password strength
  6. Rate Limit Auth Endpoints: Prevent brute force attacks
  7. Implement CSRF Protection: For session-based auth
  8. Rotate Secrets Regularly: JWT secrets, session secrets
  9. Log Security Events: Login attempts, failed auth
  10. 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

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能