Context
Users need easy way to protect FastAPI endpoints with token authentication. Standard FastAPI approach is dependency injection.
Goal
Create FastAPI dependencies for authentication and scope-based authorization.
Implementation
Acceptance Criteria
Dependencies
Notes
- Use standard FastAPI
Depends() pattern
- Extract token from
Authorization: Bearer <token> header
- Scope check: exact match (no wildcards in v0.1.0)
- Return user dict:
{'user_id': str, 'scopes': list, 'type': str, 'expires_at': datetime}
Context
Users need easy way to protect FastAPI endpoints with token authentication. Standard FastAPI approach is dependency injection.
Goal
Create FastAPI dependencies for authentication and scope-based authorization.
Implementation
genro_auth/fastapi.pymodulecreate_auth_dependency(token_manager)functioncreate_scope_dependency(required_scopes)functionHTTPBearerfor token extraction from Authorization headerHTTPException(401)for invalid/missing tokensHTTPException(403)for insufficient scopesAcceptance Criteria
require_auth = create_auth_dependency(manager)works@app.get('/protected')withDepends(require_auth)protects endpointuser['user_id'],user['scopes']Dependencies
Notes
Depends()patternAuthorization: Bearer <token>header{'user_id': str, 'scopes': list, 'type': str, 'expires_at': datetime}