Kiến trúc
Mô hình token và context
Account token, branch token, refresh token và Gateway trusted context trong CenterOS.
Mô hình token và context
Mục tiêu
Giải thích cách CenterOS phân biệt account-level branch selection với branch-scoped business access, và cách downstream services nhận context từ API Gateway.
Trạng thái hiện tại
Đã đóng:
- Single branch login trả branch-scoped
accessToken. - Multi branch login trả
accountAccessToken+branches[]. POST /api/auth/select-branchđổi account token thành branch-scopedaccessToken.- Gateway inject
trusted headerssau khi branch token hợp lệ.
Chưa đóng:
- Entitlement Service E2E consume headers qua Gateway cho
current-context.
Luồng chính
Single branch customer:
POST /api/auth/login
→ accessToken
→ nextAction = load_current_context
→ business APIsMulti branch customer:
POST /api/auth/login
→ accountAccessToken + branches[]
→ FE shows branch selection
→ POST /api/auth/select-branch
→ accessToken
→ business APIsRefresh:
refreshToken
→ POST /api/auth/refresh
→ rotated session token responseQuy tắc quan trọng
Token roles:
accountAccessToken: account-scoped token dùng cho select/switch branch.accessToken: branch-scoped token dùng cho business APIs sau khi branch context được chọn.refreshToken: session rotation token, cũng được set làm HttpOnly cookie khi applicable.
Gateway trusted headers sau branch token:
X-Account-IdX-Workspace-IdX-Member-IdX-Active-Branch-IdX-Branch-IdsX-RolesX-Token-Scope=BRANCHX-Request-IdX-Correlation-Id
Downstream services consume headers:
- Downstream services như Entitlement Service nên dùng Gateway
trusted headers. - Downstream services không nên verify client
JWTtrong normal internal runtime. - Client body
workspaceIdmust not override trusted context. - Workspace/member isolation phải đến từ trusted Gateway context, không từ client-provided body fields.
Liên quan
TODO
- Chưa đóng: Entitlement Service E2E proof cho trusted context qua Gateway.