← ClaudeAtlas

auth-patternslisted

When to activate: JWT, OAuth2, OIDC, authentication, refresh token, session, MFA, passkeys, authorization
Mattakushi432/Claude-Code-Skills-Custom-DevTools-Pack · ★ 0 · AI & Automation · score 73
Install: claude install-skill Mattakushi432/Claude-Code-Skills-Custom-DevTools-Pack
# Authentication Patterns ## JWT Implementation ```python from datetime import datetime, timedelta, timezone from jose import jwt, JWTError from passlib.hash import argon2 SECRET_KEY = os.environ["JWT_SECRET"] # 256-bit random key ALGORITHM = "HS256" def create_access_token(user_id: int) -> str: payload = { "sub": str(user_id), "iat": datetime.now(timezone.utc), "exp": datetime.now(timezone.utc) + timedelta(minutes=15), "type": "access" } return jwt.encode(payload, SECRET_KEY, algorithm=ALGORITHM) def create_refresh_token(user_id: int) -> str: payload = { "sub": str(user_id), "iat": datetime.now(timezone.utc), "exp": datetime.now(timezone.utc) + timedelta(days=30), "type": "refresh", "jti": str(uuid4()) # unique ID for revocation } return jwt.encode(payload, SECRET_KEY, algorithm=ALGORITHM) def verify_token(token: str, token_type: str) -> dict: try: payload = jwt.decode(token, SECRET_KEY, algorithms=[ALGORITHM]) if payload.get("type") != token_type: raise JWTError("Wrong token type") if is_revoked(payload.get("jti")): raise JWTError("Token revoked") return payload except JWTError: raise HTTPException(401, "Invalid token") ``` ## OAuth2 / OIDC Flow ```python # Authorization Code Flow with PKCE (public clients) import secrets, hashlib, base64 # 1. Generate PKCE challenge code_verifier = secrets.token_u