mirror of
https://github.com/duthaho/claudekit.git
synced 2026-06-10 12:14:57 +03:00
3.1 KiB
3.1 KiB
name, description
| name | description |
|---|---|
| authentication | Use when implementing JWT tokens, OAuth2 flows, session management, role-based access control (RBAC), password hashing, or multi-factor authentication. Also activate whenever code handles login, signup, token refresh, protected routes, permission checks, or user identity verification. Applies to middleware auth guards and API key authentication. |
Authentication & Authorization
When to Use
- Implementing JWT creation, verification, and refresh token flows
- Building OAuth2 authorization code or PKCE flows
- Password hashing with argon2 or bcrypt
- Role-based access control (RBAC) or permission checks
- Session management with Redis or database-backed sessions
- API key authentication for service-to-service communication
- Multi-factor authentication (TOTP, SMS, email)
When NOT to Use
- Token-free static sites or public APIs with no auth requirements
- Third-party auth services where implementation is fully managed (Auth0, Clerk) — unless customizing
- Simple scripts or CLI tools that do not need user identity
Quick Reference
| Topic | Reference | Key content |
|---|---|---|
| All auth patterns | references/patterns.md |
JWT, OAuth2, password hashing, RBAC, sessions, API keys |
| Auth flow diagrams | references/auth-flows.md |
Visual flow diagrams for OAuth2, JWT refresh, session lifecycle |
Best Practices
- Never store passwords in plain text. Use argon2id (preferred) or bcrypt with a work factor of 12+.
- Keep JWT tokens short-lived. Access tokens should expire in 15-30 minutes. Use refresh tokens for longer sessions.
- Validate tokens on every request. Never trust a token without verifying signature, expiration, and issuer.
- Use HttpOnly, Secure, SameSite cookies for web session tokens. Never store tokens in localStorage.
- Implement token refresh rotation. Invalidate old refresh tokens when a new one is issued to detect token theft.
- Separate authentication from authorization. Auth verifies identity; authz checks permissions. Keep them in separate middleware/guards.
- Rate limit auth endpoints. Login, registration, and password reset endpoints are prime brute-force targets.
- Log auth events. Record login attempts (success and failure), token refreshes, and permission denials for security auditing.
Common Pitfalls
- Storing JWTs in localStorage — vulnerable to XSS. Use HttpOnly cookies instead.
- Not rotating refresh tokens — a stolen refresh token gives permanent access.
- Hardcoding secrets — JWT signing keys and API keys must come from environment variables.
- Missing token expiration checks — always verify
expclaim server-side. - Overly broad RBAC roles — prefer granular permissions over a few broad roles.
- Not hashing API keys — store hashed API keys in the database, not plain text.
Related Skills
owasp— Security vulnerabilities in auth flowsbackend-frameworks— Framework-specific auth middlewaredatabases— Storing user credentials and sessions