auth-implementation-patterns

Implement authentication and authorization patterns for REST/GraphQL APIs with JWT and OAuth2.

1|Updated Nov 23, 2025
One-click install
npx skills add https://github.com/zmre/nix-pai --skill auth-implementation-patterns-zmre
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: auth-implementation-patterns
Source: https://github.com/zmre/nix-pai/tree/main/claude/skills/developer-essentials/auth-implementation-patterns
Command: npx skills add https://github.com/zmre/nix-pai --skill auth-implementation-patterns-zmre

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Implementing secure and reliable authentication and authorization systems is critical yet complex, often leading to vulnerabilities if not done correctly. This skill provides proven patterns and best practices to help you design and implement robust security mechanisms for your applications.

Core Features & Use Cases

  • Authentication Patterns: Guidance on implementing OAuth, JWT, and session-based authentication securely.
  • Authorization Strategies: Best practices for role-based access control (RBAC) and permission management.
  • Security Best Practices: Recommendations for protecting user data, managing credentials, and preventing common attacks.
  • Use Case: You're building a new web service and need to implement user authentication. Use this skill to choose the most appropriate authentication pattern (e.g., OAuth 2.0), design the token flow, and ensure all security best practices are followed.

Quick Start

Use the auth-implementation-patterns skill to outline the steps for implementing OAuth 2.0 for a new web application.

Frequently Asked Questions about auth-implementation-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I implement OAuth 2.0 authentication for a web application?

OAuth 2.0 authentication delegates user identity verification to a trusted provider, then issues tokens to your application. Design the authorization flow (authorization code, implicit, or client credentials), configure redirect URIs, exchange authorization codes for access tokens, and validate tokens on each API request. This pattern is ideal for delegated authentication and third-party integrations.

What's the difference between access tokens and refresh tokens?

Access tokens are short-lived credentials that grant immediate API access; refresh tokens are long-lived credentials used to obtain new access tokens without re-authentication. Issue access tokens with expiration (5–15 minutes) and refresh tokens with longer validity (days or weeks). Store refresh tokens securely server-side and rotate them on use to prevent token compromise.

How do I secure JWT tokens in a single-page application?

JWT (JSON Web Token) authentication stateless verification of user identity and permissions. Sign tokens with a secret key, include claims (user ID, roles, expiration), and validate the signature on every request. Store JWTs in httpOnly cookies or secure storage, set short expiration times, and implement token refresh logic to minimize exposure if a token is stolen.

What's the best way to implement role-based access control (RBAC)?

RBAC enforces authorization by mapping users to roles and roles to permissions. Define role hierarchies, assign roles during user creation or profile updates, embed roles in tokens or session data, and check permissions before executing sensitive operations. Implement policy enforcement at API endpoints, database queries, and business logic layers for defense-in-depth.

Can I use session-based authentication instead of token-based authentication?

Session-based authentication stores user state server-side and issues session identifiers in cookies; token-based authentication (JWT, OAuth) is stateless and scales better for APIs and distributed systems. Session authentication is simpler for monolithic web applications; token-based is preferred for microservices, mobile apps, and multi-tenant architectures. Choose based on your deployment model and scalability requirements.

How do I debug authentication failures in a REST API?

Authentication failures arise from invalid tokens, expired credentials, incorrect signatures, or missing authorization headers. Log token validation steps (signature verification, expiration checks, claim validation), inspect HTTP headers and request payloads, and test with valid and invalid tokens. Use tools like JWT decoders to inspect token contents and verify claims match expected values.