Implement BFF OAuth2 Proxy

Đang mở
#391 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
25/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
azure, fastapi, nginx, python, react, redis, typescript

Hướng nghiên cứu

Bắt đầu bằng cách xác định các điểm vào để triển khai hoặc cấu hình Nginx, oauth2-proxy và FastAPI, sau đó lần theo các route /oauth2/* và /api/*. Xem xét cách các token Microsoft Entra ID và các session được Redis hỗ trợ được kỳ vọng sẽ hoạt động. Công việc được xem là hoàn tất khi định tuyến có xác thực, xử lý session an toàn, các header token và việc xác thực JWT của FastAPI khớp với các yêu cầu.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Describe Problem

The application requires secure authentication for the SPA frontend to communicate with the FastAPI backend API. Direct OAuth2 flows from the browser (implicit flow or authorization code with PKCE stored in browser) expose tokens to XSS attacks and require complex token management in the frontend. Without a Backend-for-Frontend (BFF) pattern, the frontend must handle token refresh, storage, and secure transmission, increasing attack surface and complexity.

Suggest Solution

Implement a BFF OAuth2 proxy using oauth2-proxy  with the following architecture:

  1. Deploy oauth2-proxy as an intermediary between the SPA and backend API
    • Configure OIDC authentication with Microsoft Entra ID (Azure AD)
    • Use PKCE (code_challenge_method: S256) for secure authorization code flow
    • Enable Redis-backed session storage for horizontal scalability
  2. Configure Nginx reverse proxy with auth_request directive
    • Route /oauth2/* paths directly to oauth2-proxy
    • Enforce authentication on /api/* routes (return 401 if unauthenticated)
    • Redirect unauthenticated users to sign-in for all other routes
  3. Token injection via headers
    • Inject Authorization: Bearer <id_token> header for API requests
    • Forward X-Auth-Request-Access-Token for additional validation
  4. Secure cookie configuration
    • cookie_secure: true, cookie_httponly: true, cookie_samesite: lax
    • 15-minute token refresh interval, 1-hour session expiry
    • CSRF protection with per-request tokens
  5. Backend JWT validation in FastAPI
    • Validate tokens against Azure AD JWKS endpoint
    • Extract user claims (oid, name, email, roles) for authorization

Additional Details

Ngôn ngữ chính
TypeScript
Star
106
Fork
15
Merge trung bình
1 ngày 4 giờ
Pull request đã merge (30 ngày)
29

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của equinor/template-fastapi-react

Tất cả issue của equinor/template-fastapi-react

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.