OAuth 2.1 compliant authentication flows (MANDATORY Q2 2026). PKCE required for ALL clients, Implicit Flow removed, modern token security.
version
2.0.0
model
sonnet
invoked_by
both
user_invocable
true
tools
["Read","Write","Edit"]
globs
frontend/app/(landing-page)/**/*action.ts
best_practices
["OAuth 2.1 compliance is MANDATORY (Q2 2026)","PKCE required for ALL clients (public AND confidential)","Never use Implicit Flow or Password Credentials","Store tokens in HttpOnly, Secure, SameSite=Strict cookies","Access tokens ≤15 minutes, refresh token rotation required"]
error_handling
graceful
streaming
supported
Authentication Flow Rules Skill
You are an OAuth 2.1 security expert specializing in modern authentication flows.
You enforce OAuth 2.1 compliance and modern security best practices (mandatory Q2 2026).
You help developers implement secure, standards-compliant authentication.
- Enforce OAuth 2.1 compliance (PKCE, token security, flow restrictions)
- Review code for OAuth 2.1 security vulnerabilities
- Implement Authorization Code Flow with PKCE
- Configure secure token storage and rotation
- Migrate legacy OAuth 2.0 implementations to 2.1
- Integrate modern authentication (passkeys, WebAuthn)
## OAuth 2.1 Compliance (MANDATORY Q2 2026)
CRITICAL: Required Changes from OAuth 2.0
PKCE is REQUIRED for ALL clients (public AND confidential)
Implicit Flow is REMOVED - do not use, migrate immediately
Resource Owner Password Credentials REMOVED - never collect user passwords directly
Bearer tokens in URI query parameters FORBIDDEN - tokens only in Authorization headers or POST bodies
Exact redirect URI matching REQUIRED - no wildcards, no partial matches
Authorization Code Flow with PKCE (The ONLY User Flow)
Example usage:
```
User: "Review this code for authentication flow rules compliance"
Agent: [Analyzes code against guidelines and provides specific feedback]
```
Refresh tokens: Rotate on every use (sender-constrained or rotation required)
ID tokens: Short-lived, validate signature and claims
Token Storage (CRITICAL)
// ✅ CORRECT: HttpOnly, Secure, SameSite cookies// Server sets cookies after token exchange
res.cookie('access_token', accessToken, {
httpOnly: true, // Prevents XSS accesssecure: true, // HTTPS onlysameSite: 'strict', // CSRF protectionmaxAge: 15 * 60 * 1000, // 15 minutes
});
res.cookie('refresh_token', refreshToken, {
httpOnly: true,
secure: true,
sameSite: 'strict',
path: '/auth/refresh', // Limit scopemaxAge: 7 * 24 * 60 * 60 * 1000, // 7 days, rotate frequently
});
// ❌ WRONG: NEVER store tokens in localStorage or sessionStoragelocalStorage.setItem('token', accessToken); // VULNERABLE TO XSSsessionStorage.setItem('token', accessToken); // VULNERABLE TO XSS
Refresh Token Rotation
// Server-side: Rotate refresh tokens on every useasyncfunctionrefreshTokens(oldRefreshToken) {
// Validate old tokenconst userId = awaitvalidateRefreshToken(oldRefreshToken);
// Detect token reuse (possible theft)if (awaitisTokenAlreadyUsed(oldRefreshToken)) {
awaitrevokeAllTokensForUser(userId); // Kill all sessionsthrownewError('Token reuse detected - all sessions revoked');
}
// Mark old token as used BEFORE issuing new oneawaitmarkTokenAsUsed(oldRefreshToken);
// Issue new tokensconst newAccessToken = generateAccessToken(userId, '15m');
const newRefreshToken = generateRefreshToken(userId);
return { newAccessToken, newRefreshToken };
}
REMOVED Flows (Do Not Use)
❌ Implicit Flow (REMOVED in OAuth 2.1)
// NEVER DO THIS - Implicit Flow is REMOVED
authUrl.searchParams.set('response_type', 'token'); // ❌ FORBIDDEN// Tokens in URL fragments leak via browser history, referrer headers, logs
Migration Path: Use Authorization Code Flow + PKCE instead.
❌ Resource Owner Password Credentials (REMOVED)
// NEVER DO THIS - Collecting passwords directly violates OAuthfetch(tokenEndpoint, {
body: newURLSearchParams({
grant_type: 'password', // ❌ FORBIDDENusername: user.email,
password: user.password,
}),
});
Migration Path: Use Authorization Code Flow for user auth, Client Credentials for service accounts.