fastapi-jwt-auth

Verify JWT tokens and inject current_user into FastAPI routes.

Updated Jan 2, 2026
One-click install
npx skills add https://github.com/omerspac/advanced-to-do-app --skill fastapi-jwt-auth-omerspac
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: fastapi-jwt-auth
Source: https://github.com/omerspac/advanced-to-do-app/tree/main/Phase-2/.claude/skills/fastapi-jwt-auth
Command: npx skills add https://github.com/omerspac/advanced-to-do-app --skill fastapi-jwt-auth-omerspac

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Implements a secure, reusable JWT verification dependency for FastAPI routes to enforce strict user isolation and identity verification.

Core Features & Use Cases

  • Extracts Authorization: Bearer tokens from request headers and verifies signatures with BETTER_AUTH_SECRET.
  • Decodes JWT payloads to obtain user_id and email for downstream authorization decisions.
  • Validates that the authenticated user_id matches the route path parameter to prevent unauthorized access.
  • Provides a current_user object injected into route handlers for convenient access.
  • Standardized HTTP 401/403 error handling for missing/invalid tokens and access violations.

Quick Start

Create a FastAPI dependency that validates Authorization Bearer tokens using BETTER_AUTH_SECRET and injects current_user into route handlers.

Frequently Asked Questions about fastapi-jwt-auth

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I secure FastAPI routes with JWT authentication?

You secure FastAPI routes with JWT authentication by using a reusable dependency that extracts Bearer tokens, verifies signatures with BETTER_AUTH_SECRET, and injects the current_user object into route handlers.

How does dependency injection validate JWT tokens and enforce user isolation in FastAPI?

Dependency injection validates JWT tokens by decoding payloads to obtain user_id and email, then checks that the authenticated user_id matches the route path parameter to prevent unauthorized access and enforce strict user isolation.

Can I use BETTER_AUTH_SECRET to verify JWT signatures in FastAPI?

Yes, you can use BETTER_AUTH_SECRET to verify JWT signatures in FastAPI. The dependency extracts the Authorization Bearer token from request headers and applies signature verification for strict identity verification.

What HTTP exceptions should I handle for invalid JWT tokens in FastAPI?

For invalid JWT tokens in FastAPI, you should handle standardized HTTP 401 exceptions for missing or invalid tokens, and HTTP 403 exceptions for access violations when path parameter validation fails.

What is the best way to inject current_user into FastAPI route handlers?

The best way to inject current_user into FastAPI route handlers is through a JWT verification dependency that decodes the token payload, extracts user_id and email, and passes the object directly to your downstream functions.

Why does JWT token validation fail when user_id does not match the route path parameter?

JWT token validation fails because the dependency validates that the authenticated user_id from the decoded payload matches the route path parameter, returning an HTTP 403 access violation to prevent unauthorized cross-user access.