Bỏ qua, đến nội dung

@digiforce-nc/plugin-auth-oidc ​

Plugin xác thực qua OpenID Connect (OIDC) — hỗ trợ đăng nhập SSO với Google, Azure AD, Keycloak, Auth0 và bất kỳ Identity Provider nào tuân chuẩn OIDC. Sử dụng thư viện openid-client để giao tiếp với IdP.

Plugin này làm gì? ​

OIDCAuth kế thừa BaseAuth, đóng vai trò cầu nối giữa Digiforce và Identity Provider bên ngoài. Plugin xử lý toàn bộ luồng Authorization Code: tạo URL đăng nhập, nhận callback, trao đổi token, lấy thông tin user và tạo/liên kết tài khoản nội bộ.

Các tính năng chính ​

#Tính năngChi tiết
1Authorization Code flowRedirect user đến IdP, nhận authorization code qua callback
2CSRF protectionState parameter chứa CSRF token, lưu trong cookie digiforce_oidc
3RP-initiated logoutLưu id_token trong cookie, gửi lại IdP khi logout
4Auto-redirect SSOTự động redirect đến IdP thay vì hiện form đăng nhập
5Gateway middlewareXử lý state resolution cho kiến trúc multi-app

Luồng xác thực ​

Cấu hình ​

Tham sốKiểuMô tả
issuerstringURL của OIDC Issuer (ví dụ: https://accounts.google.com)
clientIdstringClient ID được cấp bởi IdP
clientSecretstringClient Secret
scopestringScope yêu cầu (mặc định: openid email profile)
idTokenSignedResponseAlgstringThuật toán ký id_token (mặc định: RS256)
userBindFieldstringField dùng để liên kết user (ví dụ: email)
fieldMapobjectMapping từ OIDC claims sang local user fields
httpbooleanDùng HTTP thay HTTPS cho redirect URI
portstringPort tùy chỉnh cho redirect URI
stateTokenstringSecret key để ký state parameter
exchangeBodyKeysstring[]Các key bổ sung gửi kèm khi exchange token
userInfoMethodstringPhương thức lấy userinfo: GET hoặc POST
accessTokenViastringCách gửi access_token: header, body, hoặc query
skipSSLVerificationbooleanBỏ qua kiểm tra SSL (dev only)
enableRPInitiatedLogoutbooleanBật RP-initiated logout
autoRedirectbooleanTự động redirect đến IdP khi chưa đăng nhập
public.autoSignupbooleanTự tạo tài khoản nếu user chưa tồn tại

Redirect URI cần đăng ký tại IdP:

{origin}{API_BASE_PATH}oidc:redirect

Ví dụ: https://app.example.com/api/oidc:redirect

API endpoints ​

EndpointQuyềnMô tả
oidc:getAuthUrlPublicTrả về URL để redirect đến IdP
oidc:redirectPublicCallback nhận code từ IdP, xử lý token exchange
oidc:checkRedirectPublicKiểm tra trạng thái redirect (dùng cho auto-redirect)

Thành phần client ​

Thành phầnMô tả
OIDCButtonNút "Đăng nhập bằng OIDC" trên trang login
OptionsForm cấu hình OIDC trong Settings → Authentication
OIDCAutoRedirectProviderProvider tự động redirect đến IdP nếu bật autoRedirect

Dependencies ​

PackageVai trò
openid-clientThư viện OIDC client, xử lý discovery, token exchange, userinfo
@digiforce-nc/authBase auth framework (peer)
@digiforce-nc/serverServer framework (peer)
@digiforce-nc/clientClient framework (peer)

Mục lục chi tiết ​