claudegoodies
Command

auth

From davila7

Complete authentication system with JWT tokens, OAuth2, and role-based access control.

Install

/auth

Facts

Status
Actively maintained
Last commit

Source preview

The instructions Claude Code reads when this command runs.

# FastAPI Authentication & Authorization

Complete authentication system with JWT tokens, OAuth2, and role-based access control.

## Usage

```bash
# Install auth dependencies
pip install python-jose[cryptography] passlib[bcrypt] python-multipart

# Generate secret key
openssl rand -hex 32
```

## JWT Configuration

```python
# app/core/security.py
from datetime import datetime, timedelta
from typing import Optional, Union, Any
from jose import JWTError, jwt
from passlib.context import CryptContext
from app.core.config import settings

# Password hashing
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")

# JWT settings
SECRET_KEY = settings.SECRET_KEY
ALGORITHM = "HS256"
ACCESS_TOKEN_EXPIRE_MINUTES = 30
REFRESH_TOKEN_EXPIRE_DAYS = 7

def create_access_token(
    subject: Union[str, Any], 
    expires_delta: Optional[timedelta] = None
) -> str:
    """Create JWT access token."""
    if expires_delta:
        expire = datetime.utcnow() + expires_delta
    else:
        expire = datetime.utcnow() + timedelta(minutes=ACCESS_TOKEN_EXPIRE_MINUTES)
    
    to_encode = {"exp": expire, "sub": str(subject), "type": "access"}
    encoded_jwt = jwt.encode(to_encode, SECRET_KEY, algorithm=ALGORITHM)
    return encoded_jwt

def create_refresh_token(subject: Union[str, Any]) -> str:
    """Create JWT refresh token."""
    expire = datetime.utcnow() + timedelta(days=REFRESH_TO
View full source on GitHub →

Other slash commands