API Sự kiện
Identity là một JWKS issuer theo mô hình pull; nó không tham gia vào Kafka. Các bề mặt bất đồng bộ là mail (Nodemailer), SMS (MQ-SMS), và phát sóng WebSocket.
1. Inbound
N/A. Identity chỉ phơi bày một bề mặt HTTP REST. Không có Kafka, BullMQ, hay tiếp nhận webhook.
2. Outbound — Mail
| Trigger | Template | Locale | Chuyển phát |
|---|---|---|---|
AuthenticationService.signUp (sau khi tạo) | welcome-{en|vi} | từ userProfile.locale | NodemailerComponent → SMTP |
VerifyEmailService.requestVerification | verify-email-{en|vi} | từ request | mã (6 chữ số) + URL xác thực |
ForgotPasswordService.requestReset | forgot-password-{en|vi} | từ request | mã/token đặt lại |
AuthenticationService.changePassword (sau khi cập nhật) | password-changed-{en|vi} | từ user | thông báo xác nhận |
Templates được seed bởi
identity-0004-seed-mail-configurations.ts. Có thể chỉnh sửa runtime qua bảngConfiguration(group=MAIL).
3. Outbound — SMS
| Trigger | Template | Locale |
|---|---|---|
PhoneOtpService.send (namespace=phone-auth) | phone-auth-{en|vi} | từ request |
LinkAccountService.send (namespace=add-phone) | add-phone-{en|vi} | từ request |
Provider: VN Pay SMS qua
MQSMSComponent. Templates được seed bởiidentity-0007-seed-sms-templates.ts. Cấu hình provider quaConfiguration(group=SMS).
4. Outbound — WebSocket
IdentitySocketEventServicephát sóng các sự kiện thuộc miền identity. Topics được phát quaApplicationWebSocketComponent(Redis-backed).
| Họ topic | Trigger | Đối tượng nhận |
|---|---|---|
| Trạng thái xác thực user | đăng nhập, đăng xuất, đổi trạng thái | merchant admin / observability |
| Cập nhật role/permission | thay đổi policy definition | dashboards |
| Cập nhật profile | thay đổi user profile | bản thân + admin |
Hằng số topic cụ thể được định nghĩa trong
IdentityWebSocketTopics(trongcomponents/websocket/); tham khảo source code để biết chuỗi chính xác.
5. Trạng thái OTP (Redis, không phải "events" nhưng đáng chú ý)
Các OTP service lưu trữ trạng thái trong Redis (không phải Kafka):
| Mẫu key | Mục đích | TTL |
|---|---|---|
{namespace}:otp:{identifier} | Mã đã hash | 5–15 phút mỗi flow |
{namespace}:lock:{identifier} | Khoá ở mức tài khoản sau khi vượt số lần thử tối đa | 10–15 phút |
{namespace}:session:{token} | Token phiên đã xác thực | 1–24 giờ mỗi flow |
{namespace}:cooldown:{identifier} | Cooldown gửi lại | 60s |
{namespace}:daily:{identifier} | Bộ đếm hạn ngạch hàng ngày | 24h |
Namespaces: verify-email, verify-phone, forgot-password, phone-auth, add-phone, add-email.
6. Mẫu Request-Response
Bề mặt inbound "thực" là việc các sister service pull JWKS:
| Từ | Đến | Bề mặt | Tần suất |
|---|---|---|---|
Sister VerifierApplication | Identity /jw-certs | HTTP GET | Tại thời điểm boot service + khi key-id không khớp |