技能 api-jwt-authenticator
📦

api-jwt-authenticator

v1.0.0 低风险

使用JWT身份验证保护FastAPI API

FastAPI API需要安全的身份验证来保护端点和用户数据。该技能提供有关实现JWT令牌验证、用户身份核验以及针对REST API的基于角色访问控制的指导。

支持: Claude Codex Code(CC)
🥉 79 青铜
1

下载技能 ZIP

2

在 Claude 中上传

前往 Settings → Capabilities → Skills → Upload skill

3

开启并开始使用

测试它

正在使用“api-jwt-authenticator”。 Add JWT authentication to my FastAPI user profile endpoint

预期结果:

  • 从Authorization头中提取JWT令牌
  • 使用密钥验证令牌签名
  • 验证令牌过期时间(未过期)
  • 从令牌载荷中提取用户身份
  • 为已认证请求返回用户资料
  • 对无效令牌返回401 Unauthorized

正在使用“api-jwt-authenticator”。 Create admin-only endpoint using role-based access

预期结果:

  • 从JWT令牌载荷中提取用户角色
  • 将角色与所需的'admin'权限进行比较
  • 管理员用户获得对敏感端点的访问
  • 非管理员用户收到403 Forbidden响应
  • 记录身份验证审计以进行安全监控

安全审计

低风险
v6 • 6/28/2026

Static analysis flagged Markdown backticks, JWT terminology, and HTTP authentication documentation as suspicious patterns. Review found no executable code, shell invocation, prompt injection, malware behavior, or data exfiltration in SKILL.md. The skill is a conceptual security guide and is safe to publish with low residual risk.

1
已扫描文件
136
分析行数
0
复核项
3
已忽略误报
已忽略静态误报 (3)

这些静态命中已被语义复核判定为误报,或只命中了 schema 定义里的词;这里保留展示用于透明度,但不影响质量评分。

False Positive: Markdown Formatting Flagged as Shell Execution
The flagged locations use Markdown inline code for an Authorization header and JWT claim names. They do not contain Ruby code, shell execution, command substitution, or user-controlled command construction.
The evidence is plain Markdown documentation. The surrounding text describes token format and claims, not executable Ruby or shell behavior.
False Positive: Weak Cryptography Pattern Not Confirmed
The flagged lines do not specify a weak signing algorithm or unsafe cryptographic implementation. Line 7 is the skill description, and line 128 discusses testing error response formats.
No cryptographic algorithm is named at either location. The skill recommends validating JWT signatures and expiration but does not prescribe insecure crypto.
False Positive: System Reconnaissance Pattern Not Confirmed
The flagged locations describe HTTP status handling, token structure, information disclosure avoidance, and authentication tests. They do not collect host data, enumerate files, or inspect the runtime environment.
The context is API authentication guidance. No commands, filesystem reads, environment probing, or network discovery instructions are present.
未发现安全问题
审计者: codex 查看审计历史 →

质量评分

55
架构
100
可维护性
87
内容
70
社区
95
安全
83
规范符合性

你能构建什么

保护API端点

通过JWT令牌验证和用户身份核验来保护需要认证用户访问的FastAPI端点。

实现访问控制

实施基于角色的访问控制策略,确保用户只能访问其被授权查看的资源。

设计认证系统

在充分考虑安全性的前提下,使用JWT令牌为微服务构建无状态认证模式。

试试这些提示

基础JWT保护
Use the API JWT Authenticator skill to add JWT authentication to a FastAPI endpoint. Extract the Bearer token from the Authorization header, validate the signature using a secret key, verify expiration, and return user info or 401 error.
用户特定访问
Apply the JWT Authenticator pattern to ensure users can only access their own resources. Extract user_id from token payload, compare with resource owner, and return 403 if they do not match.
基于角色的权限
Implement role-based access control using the JWT Authenticator skill. Define admin, moderator, and user roles in token claims. Create dependencies that verify user role before allowing endpoint access.
完整认证系统
Design a complete JWT authentication system for FastAPI following best practices from the API JWT Authenticator skill. Include token generation endpoint, protected routes, error handling, and production security considerations.

最佳实践

  • 始终在生产环境中使用HTTPS,防止传输过程中令牌被截获
  • 将密钥存放在环境变量或安全的密钥库中,绝不要放在源代码里
  • 设置合适的令牌过期时间,以限制令牌泄露后的暴露窗口

避免

  • 不要在URL或服务器日志中暴露原始JWT令牌,这会导致令牌被窃取
  • 避免在JWT载荷中存储敏感信息,因为任何人都可以解码令牌
  • 即使在开发或测试环境中也不要跳过令牌签名验证

常见问题

有哪些Python库适用于该技能?
使用python-jose进行JWT编码/解码,使用passlib进行密码哈希。这两者都能很好地与FastAPI依赖项集成。
JWT令牌应该持续多久?
出于安全考虑,访问令牌通常在15-30分钟后过期。更长会话请使用刷新令牌并进行合理轮换。
我可以把它用于微服务吗?
可以。JWT非常适合无状态微服务。在服务间共享密钥,或使用公钥密码学进行令牌验证。
我的令牌数据是加密的吗?
JWT令牌是签名而非加密的。任何人都可以解码载荷。绝不要在令牌中包含密码等敏感数据。
为什么我的令牌验证失败?
检查服务器时钟是否同步,验证密钥是否完全匹配,并确保令牌包含必需的声明。
这与基于会话的认证相比如何?
JWT是无状态的,可在服务间水平扩展。会话需要服务器存储,但可立即撤销。请根据架构需求选择。

开发者详情

文件结构

📄 SKILL.md