auth-implementation-patterns

Implement JWT, OAuth2, session, and RBAC authentication patterns for Node.js APIs.

Updated Jul 1, 2026
One-click install
npx skills add https://github.com/SJLee-0525/aperture --skill auth-implementation-patterns-sjlee-0525
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: auth-implementation-patterns
Source: https://github.com/SJLee-0525/aperture/tree/main/.claude/skills/auth-implementation-patterns
Command: npx skills add https://github.com/SJLee-0525/aperture --skill auth-implementation-patterns-sjlee-0525

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Building secure authentication and authorization is error-prone, and mistakes like weak password hashing, missing token expiration, or client-side-only checks create serious vulnerabilities. This Skill provides proven implementation patterns for the most common auth scenarios so you can build access control correctly the first time. ## Core Features & Use Cases - JWT & Refresh Token Flows: Generate short-lived access tokens, store hashed refresh tokens, and handle revocation for logout across devices. - Session & OAuth2 Login: Configure Express sessions backed by Redis with secure cookies, and add Google or GitHub social login via Passport.js. - Authorization Patterns: Implement role hierarchies (RBAC), permission-based checks, and resource ownership validation as Express middleware. - Use Case: When adding login to a REST API, apply the JWT pattern with bcrypt password hashing, rate-limited login endpoints, and role-based route protection to ship a secure auth layer. ## Quick Start Implement JWT authentication with refresh tokens and role-based access control for my Express API.

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 JWT authentication in Express?▼

Sign a short-lived access token with jsonwebtoken containing the user ID, email, and role, then verify it in middleware that reads the Bearer token from the Authorization header. Attach the decoded payload to the request object for downstream route handlers.

How does a refresh token flow work?▼

Issue a long-lived refresh token alongside the access token, store a hashed copy in the database with an expiration date, and exchange it for a new access token when the old one expires. Revoke stored tokens on logout to invalidate sessions.

Should I use sessions or JWT for API authentication?▼

Sessions store state server-side and suit traditional web apps with cookies, while JWTs are stateless and scale horizontally across services. The Skill covers both patterns, including Redis-backed Express sessions and token-based flows.

How do I add Google OAuth login with Passport.js?▼

Configure the GoogleStrategy with your client ID, secret, and callback URL, then find or create a user from the OAuth profile in the verify callback. After successful authentication, issue your own JWT and redirect to the frontend.

Why is storing JWTs in localStorage insecure?▼

Tokens in localStorage are accessible to any JavaScript running on the page, making them vulnerable to XSS theft. Use httpOnly, secure, sameSite cookies instead so the browser protects the credential from script access.

How do I restrict routes by user role in Express?▼

Define a role hierarchy mapping each role to the roles it includes, then write middleware that checks the authenticated user's role against the required roles. Return 403 when the user's role lacks sufficient permissions.