Giao diện
Hướng dẫn cài đặt OIDC
Hướng dẫn từng bước thiết lập xác thực OpenID Connect trong Digiforce, bao gồm cấu hình IdP phổ biến và kiểm tra kết nối.
Điều kiện tiên quyết
- Digiforce đã cài đặt và chạy ổn định
- Plugin
@digiforce-nc/plugin-auth-oidcđã được kích hoạt - Tài khoản admin trên Identity Provider (Google, Azure AD, Keycloak...)
Bước 1: Tạo authenticator trong Digiforce
- Vào Settings → Authentication → Add new
- Chọn loại OIDC
- Đặt tên authenticator (ví dụ:
google-sso,azure-ad) - Lưu lại — hệ thống sẽ tạo sẵn Redirect URI
Redirect URI cần đăng ký tại IdP có dạng:
https://your-domain.com/api/oidc:redirectBước 2: Cấu hình Identity Provider
Google Workspace
- Truy cập Google Cloud Console → APIs & Services → Credentials
- Tạo OAuth 2.0 Client ID loại Web application
- Thêm Redirect URI:
https://your-domain.com/api/oidc:redirect - Sao chép Client ID và Client Secret
- Issuer URL:
https://accounts.google.com
Azure AD (Entra ID)
- Truy cập Azure Portal → App registrations → New registration
- Redirect URI: chọn Web, nhập
https://your-domain.com/api/oidc:redirect - Vào Certificates & secrets → New client secret — sao chép giá trị
- Issuer URL:
https://login.microsoftonline.com/{tenant-id}/v2.0 - Client ID: lấy từ Application (client) ID trong Overview
Keycloak
- Tạo Client trong Realm → Clients → Create client
- Client type: OpenID Connect
- Valid redirect URIs:
https://your-domain.com/api/oidc:redirect - Bật Client authentication → sao chép Client Secret từ tab Credentials
- Issuer URL:
https://keycloak.example.com/realms/{realm-name}
Bước 3: Điền thông số vào Digiforce
Quay lại Settings → Authentication → chọn authenticator đã tạo:
| Trường | Giá trị |
|---|---|
| Issuer | URL issuer từ IdP (bắt buộc) |
| Client ID | Client ID từ IdP |
| Client Secret | Client Secret từ IdP |
| Scope | openid email profile (mặc định) |
Các trường khác có thể giữ mặc định cho lần cấu hình đầu tiên.
Bước 4: Kiểm tra đăng nhập
- Mở cửa sổ ẩn danh (incognito) của trình duyệt
- Truy cập trang đăng nhập Digiforce
- Nhấn nút Đăng nhập bằng OIDC (tên hiển thị theo authenticator)
- Hệ thống redirect đến IdP → đăng nhập → quay về Digiforce
Xác minh thành công
- User xuất hiện trong danh sách Users với email từ IdP
- Nếu bật
autoSignup, user mới được tạo tự động - Kiểm tra log server nếu có lỗi: tìm keyword
oidctrong console
Bước 5: Tùy chỉnh nâng cao (tùy chọn)
- Auto-redirect: bật
autoRedirectnếu chỉ dùng một IdP duy nhất - Field mapping: cấu hình
fieldMapđể map custom claims sang local fields - RP-initiated logout: bật
enableRPInitiatedLogoutnếu IdP hỗ trợ - HTTP/Port: điều chỉnh nếu Digiforce chạy sau reverse proxy
Xem chi tiết tại Tham số cấu hình.
Lưu ý bảo mật
- Luôn dùng HTTPS trong production — chỉ bật
httpkhi phát triển local - Không chia sẻ Client Secret — lưu trữ qua biến môi trường khi có thể
- Bật
skipSSLVerificationchỉ khi debug, không dùng trong production