Implement BFF OAuth2 Proxy

未关闭
#391 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
25/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
停滞
技术栈
azure, fastapi, nginx, python, react, redis, typescript

调研方向

首先定位 Nginx、oauth2-proxy 和 FastAPI 的部署或配置入口,然后跟踪 /oauth2/* 和 /api/* 路由。检查 Microsoft Entra ID 令牌和由 Redis 支持的会话应如何工作。完成的标准是:经过身份验证的路由、安全的会话处理、令牌标头以及 FastAPI JWT 验证均符合要求。

由索引模型根据 Issue 内容生成。

描述

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

主要语言
TypeScript
星标
106
派生
15
平均合并
1 天 4 小时
30 天内合并 PR
29

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

equinor/template-fastapi-react 的其他 Issue

查看 equinor/template-fastapi-react 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。