1---2name: auth-flow-designer3description: Design secure authentication and authorization flows — OAuth2, JWT, API keys, and RBAC for APIs4allowed-tools: [Read, Write, Bash, Grep]5effort: high6metadata:7 source: https://skillmd.com/skills/uitbreidenos/auth-flow-designer8---910## When to activate1112- Designing authentication for new API endpoints13- Implementing OAuth2 flows (authorization code, client credentials, PKCE)14- Setting up JWT token generation, validation, and refresh15- Designing role-based access control (RBAC) or ABAC policies16- Migrating from API keys to token-based auth1718## When NOT to use1920- For frontend session management (different concern)21- For SSO/SAML federation setup22- For password hashing implementation details2324## Instructions25261. **Identify auth requirements.** Who are the consumers? (users, services, third-party apps). What data sensitivity?272. **Select auth method.** API keys for server-to-server, OAuth2 + PKCE for user-facing apps, JWT for stateless microservices.283. **Design token structure.** JWT claims: sub, iss, aud, exp, iat, scope. Keep payload minimal (<1KB).294. **Define token lifecycle.** Access token: 15min expiry. Refresh token: 7-day rotation. Revocation: blacklist or token version.305. **Map scopes to endpoints.** Document which scopes are required for each endpoint in OpenAPI spec security section.316. **Design error responses.** 401 for missing/invalid token, 403 for insufficient scope, 429 for rate-limited auth attempts.327. **Security review.** Verify: HTTPS only, no tokens in URLs, proper CORS, secure token storage recommendations.3334## Example3536```yaml37# OpenAPI security definition38components:39 securitySchemes:40 bearerAuth:41 type: http42 scheme: bearer43 bearerFormat: JWT44 apiKeyAuth:45 type: apiKey46 in: header47 name: X-API-Key4849security:50 - bearerAuth: [read:users, write:users]51 - apiKeyAuth: []52```