Use caseIdentity
Select branch
Use case POST /api/auth/select-branch của Go Identity Service.
Use case: Select branch
Trạng thái
Đã đóng trong checkpoint Go Gateway + Go Identity.
Service sở hữu
Identity Service.
API Gateway yêu cầu account token context cho route này.
Endpoint
| Method | Path |
|---|---|
POST | /api/auth/select-branch |
Yêu cầu xác thực
Bearer accountAccessToken.
Không dùng refreshToken hoặc branch-scoped accessToken cho use case này.
Mục tiêu
Đổi account-scoped token + branchId thành branch-scoped accessToken.
Luồng request
Client
→ API Gateway
→ Identity Service
→ Database / token service
→ ResponseContract API
Request
{
"branchId": "00000000-0000-0000-0000-000000000000"
}Success response
{
"success": true,
"code": "AUTH_SELECT_BRANCH_SUCCESS",
"data": {
"workspace": {},
"member": {},
"branch": {},
"auth": {
"tokenType": "Bearer",
"accessToken": "branch-scoped token",
"expiresIn": 900
},
"nextAction": {
"type": "load_current_context"
}
}
}Error response
VALIDATION_ERROR:branchIdmissing/null.TOKEN_MISSING: thiếu Bearer token.TOKEN_INVALID: token sai loại, sai chữ ký, revoked, hoặc không phảiaccountAccessToken.TOKEN_EXPIRED.WORKSPACE_DISABLED,MEMBER_DISABLED.BRANCH_NOT_FOUND,BRANCH_DISABLED,BRANCH_ACCESS_DENIED.JWT_KEY_NOT_CONFIGURED.
Hành vi database
Read:
identity.auth_session: load session từ token.identity.account: check account active.identity.workspace_member: xác nhận một active customermember.identity.branch: lookupbranchId, check workspace/status.identity.branch_member: check active membership.identity.member_role,identity.branch_member_role,identity.role: lấy roles.
Write:
identity.auth_session: updateworkspace_id,member_id,active_branch_id.
Hành vi token/session
- Identity verify
accountAccessToken. branchIdphải thuộc cùngworkspacevà active membership.- Issue branch-scoped
accessToken. - Không rotate
refreshTokentrong select branch response.
Logs và observability
- Gateway access log expected:
route_id=identity-auth,service_name=identity-service. - Identity log có
path=/api/auth/select-branch. - Log không chứa token hoặc request body.
Tiêu chí nghiệm thu
- Happy path pass.
- Error path pass.
- Logs có request/correlation id nếu đi qua Gateway.
- Bruno/local smoke test pass nếu có.
TODO
- Chưa đóng: switch branch UX contract ngoài login/select flow hiện tại.