jwt-authentication
Skill110 starsChanged 9 months agoApache-2.0View on GitHub
JWT authentication implementation patterns. Use when implementing login, registration, token refresh, password reset, or any authentication/authorization system.
- Reads credentials
1 other project uses a version of this.
Adopted by
Most recently taken up by
- fatonh/symfony-skillstheir own version, first seen Jun 20, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- fatonh/symfony-skills★ 35same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository75 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- algorithmic-artSkill
- api-designSkill
- apple-notesSkill
- apple-remindersSkill
- article-writingSkill
- async-pythonSkill
- brand-guidelinesSkill
- camsnapSkill
- canvas-designSkill
- celery-tasksSkill
- claude-apiSkill
- coding-agentSkill
- content-engineSkill
- diffsSkill
- doc-coauthoringSkill
- docker-deploymentSkill
- docxSkill
- e2e-testingSkill
- email-serviceSkill
- fastapi-backendSkill
- frontend-designSkill
- frontend-slidesSkill
- gh-issuesSkill
- githubSkill
- git-workflowSkill
- graphql-apiSkill
- healthcheckSkill
- internal-commsSkill
- investor-materialsSkill
- market-researchSkill
- mcp-builderSkill
- mermaid-diagramsSkill
- microservicesSkill
- mobile-react-nativeSkill
- model-usageSkill
- nextjs-fullstackSkill
- nodejs-expressSkill
- obsidianSkill
- openai-whisperSkill
- oracleSkill
- pdfSkill
- peekabooSkill
- planning-with-filesSkill
- postgres-databaseSkill
- pptxSkill
- prisma-ormSkill
- proseSkill
- pytest-patternsSkill
- react-typescriptSkill
- redis-cachingSkill
- s3-file-storageSkill
- security-reviewSkill
- session-logsSkill
- skill-creatorSkill
- slack-gif-creatorSkill
- sqlalchemy-ormSkill
- state-managementSkill
- strategic-compactSkill
- stripe-paymentsSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
1 rule. About 0 are common, 1 is distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 117
Never store access tokens in localStorage (XSS risk)
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
JWT Authentication Patterns
Token Strategy
- Access token: short-lived (15 min), stateless JWT
- Refresh token: long-lived (7 days), stored in DB for revocation
- Storage: access in memory (JS var), refresh in httpOnly cookie
Implementation (FastAPI + Python-Jose)
# auth/tokens.py
from datetime import datetime, timedelta
from jose import JWTError, jwt
from passlib.context import CryptContext
SECRET_KEY = settings.SECRET_KEY # 32+ char random string from env
ALGORITHM = "HS256"
ACCESS_TOKEN_EXPIRE = timedelta(minutes=15)
REFRESH_TOKEN_EXPIRE = timedelta(days=7)
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
def hash_password(password: str) -> str:
return pwd_context.hash(password)
def verify_password(plain: str, hashed: str) -> bool:
return pwd_context.verify(plain, hashed)
def create_access_token(user_id: int) -> str:
return jwt.encode(
{"sub": str(user_id), "exp": datetime.utcnow() + ACCESS_TOKEN_EXPIRE, "type": "access"},
SECRET_KEY, algorithm=ALGORITHM
)
def create_refresh_token(user_id: int) -> str:
return jwt.encode(
{"sub": str(user_id), "exp": datetime.utcnow() + REFRESH_TOKEN_EXPIRE, "type": "refresh"},
SECRET_KEY, algorithm=ALGORITHM
)
def decode_token(token: str) -> dict:
try:
payload = jwt.decode(token, SECRET_KEY, algorithms=[ALGORITHM])
return payload
except JWTError:
raise HTTPException(status_code=401, detail="Invalid or expired token")Login Endpoint
@router.post("/login", response_model=TokenResponse)
async def login(form: OAuth2PasswordRequestForm = Depends(), db: AsyncSession = Depends(get_db)):
user = await get_user_by_email(db, form.username)
if not user or not verify_password(form.password, user.hashed_password):
# Same error for both cases — don't reveal which field was wrong
raise HTTPException(status_code=401, detail="Invalid credentials")
# Rate limit check (use Redis counter)
await check_login_rate_limit(user.id)
access_token = create_access_token(user.id)
refresh_token = create_refresh_token(user.id)
# Store refresh token hash in DB for revocation
await store_refresh_token(db, user.id, refresh_token)
response = JSONResponse({"access_token": access_token, "token_type": "bearer"})
response.set_cookie("refresh_token", refresh_token, httponly=True, secure=True, samesite="lax")
return responseAuth Dependency
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="/auth/login")
async def get_current_user(
token: str = Depends(oauth2_scheme),
db: AsyncSession = Depends(get_db)
) -> User:
payload = decode_token(token)
if payload.get("type") != "access":
raise HTTPException(status_code=401, detail="Invalid token type")
user = await db.get(User, int(payload["sub"]))
if not user or user.is_disabled:
raise HTTPException(status_code=401, detail="User not found or disabled")
return userRefresh Token Rotation
@router.post("/refresh")
async def refresh(request: Request, db: AsyncSession = Depends(get_db)):
refresh_token = request.cookies.get("refresh_token")
if not refresh_token:
raise HTTPException(status_code=401, detail="No refresh token")
payload = decode_token(refresh_token)
# Verify token exists in DB (revocation check)
stored = await get_refresh_token(db, refresh_token)
if not stored:
raise HTTPException(status_code=401, detail="Token revoked")
# Rotate: delete old, issue new
await delete_refresh_token(db, refresh_token)
new_access = create_access_token(int(payload["sub"]))
new_refresh = create_refresh_token(int(payload["sub"]))
await store_refresh_token(db, int(payload["sub"]), new_refresh)
response = JSONResponse({"access_token": new_access})
response.set_cookie("refresh_token", new_refresh, httponly=True, secure=True, samesite="lax")
return responseRules
- httpOnly cookies for refresh tokens (XSS can't steal them)
- Never store access tokens in localStorage (XSS risk)
- Refresh token rotation: old token invalidated immediately on use
- Rate limit login: 5 attempts per IP per 15 minutes
- Same error message for wrong email AND wrong password
- Logout must invalidate refresh token in DB
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

