fastapi-security

Implement JWT authentication, RBAC, CORS, rate limiting, and security headers for FastAPI applications.

1|Updated Mar 10, 2026
One-click install
npx skills add https://github.com/aleonsa/claude-config --skill fastapi-security
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: fastapi-security
Source: https://github.com/aleonsa/claude-config/tree/main/claude/skills/fastapi-security
Command: npx skills add https://github.com/aleonsa/claude-config --skill fastapi-security

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires python-jose, passlib, fastapi, pydantic, slowapi, python-magic, and includes scripts (resource) and references (resource) components.

What problem does it solve?

This Skill provides a comprehensive set of tools and patterns to secure FastAPI applications, addressing authentication, authorization, and common web vulnerabilities.

Core Features & Use Cases

  • JWT Authentication: Implement secure token-based authentication using python-jose.
  • Role-Based Access Control (RBAC): Define and enforce granular permissions for different user roles.
  • Security Hardening: Configure CORS, rate limiting, security headers, and input validation to protect against common attacks.
  • Use Case: Secure a new FastAPI backend for a web application by implementing user login, protecting sensitive endpoints with role checks, and ensuring all communication is safe from common web exploits.

Quick Start

Implement JWT authentication in your FastAPI application using the provided code examples for token generation, decoding, and password hashing.

Frequently Asked Questions about fastapi-security

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

FAQPage Schema
How do I implement JWT authentication in FastAPI?

JWT authentication in FastAPI is implemented using python-jose for token generation and decoding, combined with passlib for secure password hashing. This Skill provides code examples for OAuth2 token generation and validation endpoints.

How do I set up role-based access control in FastAPI?

Role-based access control in FastAPI is configured by defining granular permission checks for different user roles. This Skill implements RBAC patterns to enforce permissions and protect sensitive endpoints based on decoded JWT token claims.

Can I add rate limiting and security headers to a FastAPI application?

Rate limiting and security headers are configured using slowapi and custom middleware. This Skill hardens FastAPI applications by applying slowapi rate limits, setting HTTP security headers, and validating inputs with Pydantic against common web exploits.

What is the best way to configure CORS for a secure FastAPI backend?

Configuring CORS for a secure FastAPI backend involves applying strict cross-origin resource sharing policies via middleware. This Skill provides production hardening patterns including CORS setup, input validation, and security header enforcement.

Does this approach work with OAuth2 and Pydantic for API security?

Yes, the approach integrates OAuth2 password flows with Pydantic for API security validation. It uses python-jose for JWT management and Pydantic models to validate incoming requests, ensuring secure API development and protection against common attacks.