fastapi-auth-patterns
Implement and validate FastAPI authentication strategies including JWT tokens, OAuth2 password flows, OAuth2 scopes for permissions, and Supabase integration. Use when implementing authentication, securing endpoints, handling user login/signup, managing permissions, integrating OAuth providers, or when user mentions JWT, OAuth2, Supabase auth, protected routes, access control, role-based permissions, or authentication errors.
What this skill does
# FastAPI Authentication Patterns
**Purpose:** Autonomously implement, validate, and debug FastAPI authentication systems with multiple strategies.
**Activation Triggers:**
- Implementing user authentication
- Securing API endpoints
- JWT token generation/validation issues
- OAuth2 flow configuration
- Permission and role-based access control
- Supabase authentication integration
- Authentication errors (401, 403)
- Password hashing and security
**Key Resources:**
- `scripts/setup-jwt.sh` - Initialize JWT authentication system
- `scripts/validate-auth.sh` - Validate authentication configuration
- `templates/jwt_auth.py` - Complete JWT authentication implementation
- `templates/oauth2_flow.py` - OAuth2 password flow with scopes
- `templates/supabase_auth.py` - Supabase integration for FastAPI
- `examples/protected_routes.py` - Protected endpoint patterns
- `examples/permission_system.py` - Role and permission-based access
## Authentication Strategies
### 1. JWT Token Authentication
**Use When:**
- Need stateless authentication
- Building API for mobile/web clients
- Require token expiration control
- Implementing refresh token patterns
**Setup:**
```bash
./scripts/setup-jwt.sh
```
**Core Components:**
- Password hashing with Argon2 (pwdlib)
- JWT token generation with expiration
- Token validation and user extraction
- Secure secret key management
**Implementation Pattern:**
```python
# Hash passwords (never store plaintext)
password_hash = PasswordHash.recommended()
hashed = password_hash.hash(plain_password)
# Generate JWT token
def create_access_token(data: dict, expires_delta: timedelta):
to_encode = data.copy()
expire = datetime.now(timezone.utc) + expires_delta
to_encode.update({"exp": expire})
return jwt.encode(to_encode, SECRET_KEY, algorithm="HS256")
# Validate token and extract user
async def get_current_user(token: str = Depends(oauth2_scheme)):
payload = jwt.decode(token, SECRET_KEY, algorithms=["HS256"])
username = payload.get("sub")
return get_user(username)
```
**Key Points:**
- Use environment variables for SECRET_KEY
- Default token expiration: 30 minutes
- Store username in "sub" claim
- Validate token signature and expiration
### 2. OAuth2 Password Flow
**Use When:**
- Building first-party applications
- Need username/password authentication
- Following OAuth2 standards
- Integrating with OpenAPI documentation
**Template:** `templates/oauth2_flow.py`
**Flow:**
1. User submits credentials via `OAuth2PasswordRequestForm`
2. Server verifies password hash
3. Server returns signed JWT access token
4. Client includes token in Authorization header
**Security Scheme:**
```python
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token")
@app.post("/token")
async def login(form_data: OAuth2PasswordRequestForm = Depends()):
user = authenticate_user(form_data.username, form_data.password)
access_token = create_access_token(data={"sub": user.username})
return {"access_token": access_token, "token_type": "bearer"}
```
### 3. OAuth2 Scopes (Permissions)
**Use When:**
- Need fine-grained permission control
- Implementing role-based access
- Building multi-tenant systems
- Following least-privilege principle
**Template:** See `templates/oauth2_flow.py` (includes scopes)
**Define Scopes:**
```python
oauth2_scheme = OAuth2PasswordBearer(
tokenUrl="token",
scopes={
"me": "Read information about current user",
"items": "Read items",
"items:write": "Create and modify items"
}
)
```
**Encode Scopes in Token:**
```python
# During login, add user's scopes to token
token_data = {"sub": username, "scopes": user.scopes}
access_token = create_access_token(token_data)
```
**Protect Endpoints with Scopes:**
```python
async def get_current_user(
security_scopes: SecurityScopes,
token: str = Depends(oauth2_scheme)
):
# Validate token has required scopes
for scope in security_scopes.scopes:
if scope not in token_data.scopes:
raise HTTPException(401, "Not enough permissions")
@app.get("/users/me/items/")
async def read_items(
current_user: User = Security(get_current_active_user, scopes=["items"])
):
return current_user.items
```
### 4. Supabase Authentication
**Use When:**
- Using Supabase as backend
- Need managed authentication service
- Want OAuth providers (Google, GitHub, etc.)
- Require user management dashboard
**Template:** `templates/supabase_auth.py`
**Setup:**
```python
from supabase import create_client, Client
supabase: Client = create_client(
os.getenv("SUPABASE_URL"),
os.getenv("SUPABASE_KEY")
)
```
**Sign Up:**
```python
# Email/password signup
response = supabase.auth.sign_up({
"email": "[email protected]",
"password": "secure_password",
"options": {"data": {"full_name": "John Doe"}}
})
```
**Sign In:**
```python
response = supabase.auth.sign_in_with_password({
"email": "[email protected]",
"password": "secure_password"
})
access_token = response.session.access_token
```
**Validate Token in FastAPI:**
```python
async def get_current_user(token: str = Depends(oauth2_scheme)):
# Validate Supabase JWT token
user = supabase.auth.get_user(token)
return user
```
**Integration Pattern:**
- Store Supabase session in HTTP-only cookies (server-side)
- Use PKCE flow for OAuth providers
- Implement token refresh logic
- Leverage Supabase RLS policies for data access
## Validation Workflow
### 1. Run Authentication Validator
```bash
./scripts/validate-auth.sh
```
**Checks Performed:**
- ✅ Required packages installed (fastapi, python-jose[cryptography], passlib[argon2], pwdlib)
- ✅ Environment variables set (SECRET_KEY, ALGORITHM, ACCESS_TOKEN_EXPIRE_MINUTES)
- ✅ Security scheme configured correctly
- ✅ Password hashing implemented
- ✅ Token generation and validation functions present
- ✅ Protected endpoints use proper dependencies
### 2. Common Issues & Fixes
**Missing SECRET_KEY:**
```bash
# Generate secure random key
openssl rand -hex 32
# Add to .env
echo 'SECRET_KEY=your_generated_key' >> .env
```
**Token Expired (401):**
- Increase ACCESS_TOKEN_EXPIRE_MINUTES
- Implement refresh token pattern
- Check server/client time sync
**Invalid Credentials:**
- Verify password hashing algorithm matches
- Check user exists in database
- Validate password comparison logic
**Missing Permissions (403):**
- Verify user has required scopes
- Check scope encoding in token
- Validate SecurityScopes configuration
**Supabase Connection Failed:**
- Verify SUPABASE_URL and SUPABASE_KEY
- Check project settings in Supabase dashboard
- Validate network connectivity
## Protected Routes Pattern
**Example:** `examples/protected_routes.py`
```python
# Public endpoint (no auth)
@app.get("/")
async def root():
return {"message": "Public endpoint"}
# Protected endpoint (requires authentication)
@app.get("/users/me")
async def read_users_me(current_user: User = Depends(get_current_user)):
return current_user
# Protected with specific permission
@app.post("/items/")
async def create_item(
item: Item,
current_user: User = Security(get_current_active_user, scopes=["items:write"])
):
return create_item_for_user(current_user, item)
# Admin-only endpoint
@app.delete("/users/{user_id}")
async def delete_user(
user_id: int,
current_user: User = Depends(get_current_admin_user)
):
return delete_user_by_id(user_id)
```
## Permission System Pattern
**Example:** `examples/permission_system.py`
**Role-Based Access Control (RBAC):**
```python
class Role(str, Enum):
ADMIN = "admin"
USER = "user"
GUEST = "guest"
class User(BaseModel):
username: str
role: Role
permissions: List[str]
def has_permission(user: User, required_permission: str) -> bool:
# Admins have all permissions
if user.role == Role.ADMIN:
return True
return required_permission in user.permissions
async def require_permission(permission: str):
async defRelated in Backend & APIs
jfrog
IncludedInteract with the JFrog Platform via the JFrog CLI and REST/GraphQL APIs. Use this skill when the user wants to manage Artifactory repositories, upload or download artifacts, manage builds, configure permissions, manage users and groups, work with access tokens, configure JFrog CLI servers, search artifacts, manage properties, set up replication, manage JFrog Projects, run security audits or scans, look up CVE details, query exposures scan results from JFrog Advanced Security, manage release bundles and lifecycle operations, aggregate or export platform data, or perform any JFrog Platform administration task. Also use when the user mentions jf, jfrog, artifactory, xray, distribution, evidence, apptrust, onemodel, graphql, workers, mission control, curation, advanced security, exposures, or any JFrog product name.
cupynumeric-migration-readiness
IncludedPre-migration readiness assessor for porting NumPy to cuPyNumeric. Use BEFORE substantial porting work begins when the user asks whether code will scale on GPU, whether they should migrate to cuPyNumeric, which NumPy patterns transfer cleanly, what must be refactored before porting, or mentions pre-port assessment, scaling analysis, or refactor planning. Inspect the user's source code, look up NumPy usage, cross-reference the cuPyNumeric API support manifest, and distinguish distributed-scaling-friendly patterns from blockers such as unsupported APIs, scalar synchronization, host round-trips, Python/object-heavy control flow, shape/data-dependent branching, and in-place mutation hazards. Produce a verdict of READY, LIGHT REFACTOR, SIGNIFICANT REFACTOR, or NOT RECOMMENDED, with concrete refactor pointers.
alibabacloud-data-agent-skill
IncludedInvoke Alibaba Cloud Apsara Data Agent for Analytics via CLI to perform natural language-driven data analysis on enterprise databases. Data Agent for Analytics is an intelligent data analysis agent developed by Alibaba Cloud Database team for enterprise users. It automatically completes requirement analysis, data understanding, analysis insights, and report generation based on natural language descriptions. This tool supports: discovering data resources (instances/databases/tables) managed in DMS, initiating query or deep analysis sessions, real-time progress tracking, and retrieving analysis conclusions and generated reports. Use this Skill when users need to query databases, analyze data trends, generate data reports, ask questions in natural language, or mention "Data Agent", "data analysis", "database query", "SQL analysis", "data insights".
token-optimizer
IncludedReduce OpenClaw token usage and API costs through smart model routing, heartbeat optimization, budget tracking, and native 2026.2.15 features (session pruning, bootstrap size limits, cache TTL alignment). Use when token costs are high, API rate limits are being hit, or hosting multiple agents at scale. The 4 executable scripts (context_optimizer, model_router, heartbeat_optimizer, token_tracker) are local-only — no network requests, no subprocess calls, no system modifications. Reference files (PROVIDERS.md, config-patches.json) document optional multi-provider strategies that require external API keys and network access if you choose to use them. See SECURITY.md for full breakdown.
resend-cli
IncludedUse this skill when the task is specifically about operating Resend from an AI agent, terminal session, or CI job via the official resend CLI: installing/authenticating the CLI, sending/listing/updating/cancelling emails, batch sends, domains and DNS, webhooks and local listeners, inbound receiving, contacts, topics, segments, broadcasts, templates, API keys, profiles, or debugging Resend CLI/API failures. Trigger on mentions of Resend CLI, `resend`, `resend doctor`, `resend emails send`, `resend domains`, `resend webhooks listen`, `resend emails receiving`, or agent-friendly terminal automation.
alibabacloud-odps-maxframe-coding
IncludedUse this skill for MaxFrame SDK development and documentation navigation on Alibaba Cloud MaxCompute (ODPS). Helps answer MaxFrame API, concept, official example, and supported pandas API questions; create data processing programs; read/write MaxCompute tables; debug jobs (remote or local); and build custom DPE runtime images. Trigger when users mention MaxFrame, MaxCompute with MaxFrame, ODPS table processing, DPE runtime, MaxFrame docs/examples, DataFrame/Tensor operations, or GPU runtime setup. Works for both English and Chinese queries about Alibaba Cloud data processing with MaxFrame.