xiaohongshu
xiaohongshu
clerk-token-ops
Automates Clerk JWT token generation, validation, and export for FastAPI integration tests. Use when an agent must refresh tokens, verify JWT templates, or unblock authentication workflows without breaking environment state.
Full skill instructions
This skill gives Claude Code agents a repeatable, zero-surprise playbook for generating Clerk JWTs, exporting them into the Windows PowerShell environment, and validating authentication against the FastAPI backend. It encodes the exact fixes from the November 2025 incidents (missing templates, parser errors, stale tokens) so future runs avoid the same failures.
Use this skill whenever the task involves:
.env.local and PowerShell sessions stay in sync (CLERK_SECRET_KEY, CLERK_TOKEN).server-token).scripts/get_clerk_token.py or Set-ClerkToken.ps1 safely.scripts/Set-ClerkToken.ps1.user_35KgiAcvIC0tdtFvJUN1vDkrNYc). Angle brackets or placeholders break PowerShell parsing..env.local exists and contains CLERK_SECRET_KEY, CLERK_ISSUER, CLERK_PEM_PUBLIC_KEY, and CLERK_ISSUER_ID..env.local; environment variables load only once per process.Test-Path .env.local and open the file if missing keys.CLERK_JWT_AUDIENCE stays commented out; session tokens lack aud.powershell -File .\scripts\Set-ClerkToken.ps1 -ListTemplatesserver-token exists; if missing, create it in the Clerk dashboard with RS256 signing.powershell -File .\scripts\Set-ClerkToken.ps1 -UserId <ACTUAL_USER_ID> -Template server-token [-Persist]echo $env:CLERK_TOKENpython scripts/get_clerk_token.py --env-file .env.local --user-id ... --template server-token --print-session for debugging.uv run python main/scripts/test_clerk_auth.py "$env:CLERK_TOKEN" fixtures/test_urs.txtcurl -H "Authorization: Bearer $env:CLERK_TOKEN" http://localhost:8000/jobs -d @payload.json -H "Content-Type: application/json"logs/audit/jobs/audit_*.jsonl to ensure the sub (user ID) and token_iat fields are captured (ALCOA+ compliance)..env.local contains correct Clerk keys and issuer URLs.scripts/get_clerk_token.py runs without HTTP errors and prints JWT.scripts/Set-ClerkToken.ps1 outputs success messages (no [System.Char] errors).$env:CLERK_TOKEN is non-empty and recent (token_iat within 60 seconds).user_id from JWT sub claim.| Symptom | Root Cause | Fix |
|---|---|---|
Method invocation failed because [System.Char] does not contain a method named 'Trim' | PowerShell treated helper output as char array | Use the patched Set-ClerkToken.ps1 (Nov 2025). If issue recurs, wrap extraction with [string] and ensure token line exists. |
Unable to parse JWT from helper output | Helper didnt emit token (HTTP error, wrong template, or env vars missing) | Re-run helper with --print-session and check .env.local secrets; confirm template name matches exactly. |
Token validation failed: Token is missing the "aud" claim | Audience verification enabled | Comment out CLERK_JWT_AUDIENCE and ensure JWT decode options set verify_aud=False. |
401 Unauthorized: Token expired | Delay between generation and use | Regenerate token and chain tests immediately (<60s). Automate generation/test pipeline if needed. |
500 Internal Server Error: Authentication system not configured | FastAPI didnt load .env.local | Load dotenv at the top of main/api/app.py before other imports; restart server. |
# 1. List templates (sanity check)
powershell -File .\scripts\Set-ClerkToken.ps1 -ListTemplates
# 2. Export fresh token for known test user
powershell -File .\scripts\Set-ClerkToken.ps1 -UserId user_35KgiAcvIC0tdtFvJUN1vDkrNYc -Template server-token -Persist
# 3. Verify environment
$env:CLERK_TOKEN
# 4. Exercise FastAPI endpoint (token expires fast!)
uv run python main/scripts/test_clerk_auth.py "$env:CLERK_TOKEN" fixtures/test_urs.txt
# 5. Tail audit logs for attribution
Get-Content logs/audit/jobs/audit_$(Get-Date -Format yyyyMMdd).jsonl -Tail 3
docker compose -f docker-compose.dev.yml up --build api worker after refreshing tokens.$env:CLERK_TOKEN is available to downstream pytest or uv run commands.main/docs/guides/CLERK_INTEGRATION_TESTING.md and note version in this skill.scripts/get_clerk_token.py - Python helper hitting Clerk Backend API.scripts/Set-ClerkToken.ps1 - PowerShell wrapper for Windows devs.main/docs/guides/CLERK_INTEGRATION_TESTING.md - Deep dive guide.Maintainer: Compliance/Test Enablement Team
Last Updated: 2025-11-16
Status: ✅ Ready for Claude Code agents
xiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience