api-security

Implement OAuth2 JWT authentication and role-based access control in FastAPI applications.

Updated Aug 23, 2026
One-click install
npx skills add https://github.com/arinbalyan/config --skill api-security-arinbalyan
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: api-security
Source: https://github.com/arinbalyan/config/tree/main/skills/api-security
Command: npx skills add https://github.com/arinbalyan/config --skill api-security-arinbalyan

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill secures FastAPI applications by implementing robust authentication and authorization patterns, reducing security drift and hard-to-maintain security logic.

Core Features & Use Cases

  • OAuth2PasswordBearer-based JWT authentication workflows
  • Password hashing with passlib and bcrypt
  • Enforce HTTPS in production using TLS context
  • Prevent SQL-related injection when used with ORMs through parameterized queries
  • CSRF protection and secure cookie settings
  • Rotate refresh tokens and implement short-lived JWTs
  • Environment-based secrets management and centralized logging
  • Role-based access control and proper authorization checks

Quick Start

Start by integrating the provided patterns into a FastAPI app and secure a sample endpoint with OAuth2 and a refresh token flow.

Frequently Asked Questions about api-security

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

FAQPage Schema
How do I implement OAuth2 and JWT authentication in a FastAPI application?

FastAPI JWT authentication uses OAuth2PasswordBearer workflows to issue short-lived tokens and rotate refresh tokens, ensuring secure session management without hardcoded credentials.

What is the best way to hash passwords securely in FastAPI?

Hash passwords in FastAPI using passlib with bcrypt to securely store and verify user credentials, preventing plaintext exposure and reducing security drift in authentication logic.

Does this approach support CSRF protection and secure cookies for FastAPI?

FastAPI CSRF protection and secure cookies are configured to prevent cross-site request forgery attacks, safeguarding session state and ensuring safe error handling in production environments.

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

Role-based access control in FastAPI enforces authorization checks on endpoints, ensuring users only access resources permitted by their assigned role and token scope during API requests.

How do I manage environment-based secrets for FastAPI authentication in production?

Environment-based secrets management for FastAPI loads credentials from environment variables, enforces HTTPS with TLS context, and centralizes logging to monitor authentication and prevent security drift.