.agents/skills/auth-flow-validation/SKILL.md
Authentication flow validation between frontend and backend. Covers JWT, OAuth2, token refresh, and session management sync. USE WHEN: user asks about "auth integration", "JWT validation", "token refresh", "401 handling", "authentication flow", "login integration" DO NOT USE FOR: security auditing - use security skills, OAuth provider setup - use authentication skills
npx skillsauth add d-subrahmanyam/deno-fresh-microservices auth-flow-validationInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
security skillsoauth2 skilljwt skillDeep Knowledge: Use
mcp__documentation__fetch_docswith technology:jwtoroauth2for protocol details.
┌─────────────────────────────────────────────────────────────────────┐
│ AUTHENTICATION FLOW │
├─────────────────────────────────────────────────────────────────────┤
│ │
│ Frontend Backend │
│ ┌──────────────┐ ┌──────────────┐ │
│ │ 1. Login │──────────→│ POST /auth │ │
│ │ Form │ │ /login │ │
│ └──────────────┘ └──────┬───────┘ │
│ ↑ │ │
│ │ ↓ │
│ ┌──────────────┐ ┌──────────────┐ │
│ │ 2. Store │←──────────│ Return JWT │ │
│ │ Tokens │ │ + Refresh │ │
│ └──────────────┘ └──────────────┘ │
│ │ │
│ ↓ │
│ ┌──────────────┐ ┌──────────────┐ │
│ │ 3. API Call │──────────→│ Validate JWT │ │
│ │ + Auth Header│ │ │ │
│ └──────────────┘ └──────┬───────┘ │
│ ↑ │ │
│ │ 401 Unauthorized │ │
│ │←─────────────────────────┤ │
│ │ │ │
│ ↓ │ │
│ ┌──────────────┐ ┌──────────────┐ │
│ │ 4. Refresh │──────────→│ POST /auth │ │
│ │ Token │ │ /refresh │ │
│ └──────────────┘ └──────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────┘
| Step | Frontend | Backend | Validation | |------|----------|---------|------------| | Endpoint | POST /auth/login | POST /auth/login | Path match | | Request Body | { email, password } | { email, password } | Schema match | | Response | { accessToken, refreshToken, user } | Same structure | Type match | | Token Storage | localStorage/httpOnly cookie | Expects cookie or header | Method match | | Error Response | Handle 401, 400 | Returns structured error | Error format |
| Step | Frontend | Backend | Validation | |------|----------|---------|------------| | Trigger | 401 response intercepted | Returns 401 on expired | Consistent behavior | | Endpoint | POST /auth/refresh | POST /auth/refresh | Path match | | Request | refreshToken in body/cookie | Expects same location | Method match | | Response | New accessToken | Returns new token | Structure match | | Retry | Original request retried | Accepts new token | Flow complete |
// Backend expects: HttpOnly cookie
res.cookie('accessToken', token, {
httpOnly: true,
secure: true,
sameSite: 'strict',
});
// Frontend stores: localStorage (MISMATCH!)
localStorage.setItem('accessToken', response.accessToken);
// Frontend should: Let backend set cookie
// No manual storage needed - cookie sent automatically
// Backend expects
Authorization: Bearer eyJhbGciOiJIUzI1NiIs...
// Frontend sends (WRONG)
Authorization: eyJhbGciOiJIUzI1NiIs... // Missing "Bearer "
// Frontend sends (WRONG)
Authorization: bearer eyJhbGciOiJIUzI1NiIs... // Wrong case
// Correct frontend implementation
const token = getAccessToken();
fetch('/api/users', {
headers: {
'Authorization': `Bearer ${token}`,
},
});
// Backend expects: Cookie
app.post('/auth/refresh', (req, res) => {
const refreshToken = req.cookies.refreshToken; // From cookie
});
// Frontend sends: Body (MISMATCH!)
fetch('/auth/refresh', {
method: 'POST',
body: JSON.stringify({ refreshToken }), // Wrong!
});
// Correct: Cookie sent automatically
fetch('/auth/refresh', {
method: 'POST',
credentials: 'include', // Include cookies
});
// Backend: Token expires after 15 minutes
const token = jwt.sign(payload, secret, { expiresIn: '15m' });
// Frontend: No expiration check (BAD)
function makeAuthenticatedRequest() {
return fetch('/api/data', {
headers: { Authorization: `Bearer ${token}` },
});
}
// Frontend: Check expiration before request (GOOD)
function makeAuthenticatedRequest() {
const token = getAccessToken();
if (isTokenExpired(token)) {
await refreshAccessToken();
}
return fetch('/api/data', {
headers: { Authorization: `Bearer ${getAccessToken()}` },
});
}
// Helper to check expiration
function isTokenExpired(token: string): boolean {
const payload = JSON.parse(atob(token.split('.')[1]));
return payload.exp * 1000 < Date.now();
}
import axios from 'axios';
const api = axios.create({
baseURL: '/api',
});
// Request interceptor - add token
api.interceptors.request.use((config) => {
const token = getAccessToken();
if (token) {
config.headers.Authorization = `Bearer ${token}`;
}
return config;
});
// Response interceptor - handle 401
api.interceptors.response.use(
(response) => response,
async (error) => {
const originalRequest = error.config;
if (error.response?.status === 401 && !originalRequest._retry) {
originalRequest._retry = true;
try {
const newToken = await refreshAccessToken();
originalRequest.headers.Authorization = `Bearer ${newToken}`;
return api(originalRequest);
} catch (refreshError) {
// Refresh failed - logout user
logout();
return Promise.reject(refreshError);
}
}
return Promise.reject(error);
}
);
async function fetchWithAuth(url: string, options: RequestInit = {}) {
let token = getAccessToken();
// Check if token expired
if (isTokenExpired(token)) {
token = await refreshAccessToken();
}
const response = await fetch(url, {
...options,
headers: {
...options.headers,
Authorization: `Bearer ${token}`,
},
});
// Handle 401 (token rejected by server)
if (response.status === 401) {
token = await refreshAccessToken();
return fetch(url, {
...options,
headers: {
...options.headers,
Authorization: `Bearer ${token}`,
},
});
}
return response;
}
import { QueryClient } from '@tanstack/react-query';
const queryClient = new QueryClient({
defaultOptions: {
queries: {
retry: (failureCount, error) => {
// Don't retry on 401
if (error instanceof Response && error.status === 401) {
return false;
}
return failureCount < 3;
},
},
},
});
// Global error handler
queryClient.setDefaultOptions({
mutations: {
onError: (error) => {
if (error instanceof Response && error.status === 401) {
// Redirect to login
window.location.href = '/login';
}
},
},
});
components:
securitySchemes:
bearerAuth:
type: http
scheme: bearer
bearerFormat: JWT
security:
- bearerAuth: []
paths:
/users:
get:
security:
- bearerAuth: []
responses:
401:
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
components:
securitySchemes:
cookieAuth:
type: apiKey
in: cookie
name: accessToken
paths:
/users:
get:
security:
- cookieAuth: []
## Auth Flow Validation Report
### Login Flow
| Check | Status | Details |
|-------|--------|---------|
| Endpoint path | OK | POST /auth/login |
| Request body | OK | { email, password } |
| Response structure | WARNING | Missing `expiresIn` field |
| Token storage | ERROR | Frontend uses localStorage, backend expects cookie |
### Token Refresh Flow
| Check | Status | Details |
|-------|--------|---------|
| Trigger condition | OK | 401 intercepted |
| Refresh endpoint | OK | POST /auth/refresh |
| Token placement | ERROR | Frontend sends in body, backend expects cookie |
| Retry mechanism | OK | Original request retried |
### Recommendations
1. **Critical**: Change token storage to httpOnly cookies
2. **Critical**: Update refresh to use credentials: 'include'
3. **Warning**: Add expiresIn to login response for proactive refresh
| Anti-Pattern | Why It's Bad | Correct Approach | |--------------|--------------|------------------| | localStorage for tokens | XSS vulnerability | Use httpOnly cookies | | No token refresh | Poor UX, forced logout | Implement refresh flow | | Refresh on every request | Performance | Refresh on 401 or near expiry | | No logout on refresh fail | Security risk | Clear tokens and redirect | | Hardcoded token expiry | Drift with backend | Parse from token or response |
| Issue | Likely Cause | Solution |
|-------|--------------|----------|
| 401 on login | Wrong credentials format | Check request body schema |
| 401 after refresh | Refresh token also expired | Re-authenticate user |
| Infinite refresh loop | Not marking retried requests | Add retry flag |
| CORS on auth endpoints | Missing credentials config | Add credentials: 'include' |
| Token not sent | Authorization header format | Check "Bearer " prefix |
development
Guidelines for building high-performance APIs with Fastify and TypeScript, covering validation, Prisma integration, and testing best practices
development
FastAPI modern Python web framework. Covers routing, Pydantic models, dependency injection, and async support. Use when building Python APIs. USE WHEN: user mentions "fastapi", "pydantic", "async python api", "python rest api", asks about "dependency injection python", "python openapi", "python swagger", "async endpoints", "python api validation", "fastapi middleware" DO NOT USE FOR: Django apps - use `django` instead, Flask apps - use `flask` instead, synchronous Python APIs without type hints, GraphQL-only APIs
tools
FastAPI integration testing specialist. Covers synchronous TestClient, async httpx AsyncClient, dependency injection overrides, auth testing (JWT, OAuth2, API keys), WebSocket testing, file uploads, background tasks, middleware testing, and HTTP mocking with respx, responses, and pytest-httpserver. USE WHEN: user mentions "FastAPI test", "TestClient", "httpx async test", "dependency override test", "respx mock", asks about testing FastAPI endpoints, authentication in tests, or HTTP client mocking. DO NOT USE FOR: Django - use `pytest-django`; pytest internals - use `pytest`; Container infrastructure - use `testcontainers-python`
development
Expert in FastAPI Python development with best practices for APIs and async operations