Bỏ qua, đến nội dung

@digiforce-nc/plugin-auth-apple

Plugin xác thực qua Sign in with Apple — cho phép user đăng nhập bằng Apple ID. Sử dụng openid-clientjsonwebtoken để xử lý luồng OAuth 2.0 với đặc thù form_post response mode của Apple.

Plugin này làm gì?

AppleAuth kế thừa BaseAuth, triển khai luồng Authorization Code của Apple với response_mode: form_post. Apple gửi authorization code và thông tin user (nếu lần đầu) qua HTTP POST thay vì query string — đây là đặc thù riêng của Apple so với OIDC thông thường.

Đặc thù Sign in with Apple

#Đặc thùChi tiết
1form_post responseApple POST form data (không redirect query) — cần gateway middleware
2User info chỉ lần đầuApple gửi tên user trong user JSON chỉ khi authorize lần đầu
3State trong cookieState (CSRF) lưu trong cookie digiforce_apple
4id_token decodeClaims lấy từ decode JWT id_token, không qua userinfo endpoint
5External redirectHỗ trợ redirectUrl tùy chỉnh sau đăng nhập thành công

Luồng xác thực

Cấu hình

Tham sốKiểuMô tả
clientIdstringApple Services ID (ví dụ: com.example.app.auth)
clientSecretstringJWT secret tạo từ Apple private key
redirectUrlstringURL redirect tùy chỉnh sau đăng nhập (optional)
scopestringScope yêu cầu (mặc định: email name)
idTokenSignedResponseAlgstringThuật toán ký id_token (mặc định: RS256)
fieldMapobjectMapping từ Apple claims sang local user fields
userBindFieldstringField dùng để liên kết user (ví dụ: email)
public.autoSignupbooleanTự tạo tài khoản nếu user chưa tồn tại

Lưu ý về Apple client secret

Apple client secret là JWT ngắn hạn (tối đa 6 tháng), tạo từ:

  • Key ID — từ Apple Developer Console
  • Team ID — Apple Developer Team
  • Private Key — file .p8 tải từ Apple

API endpoints

EndpointQuyềnMô tả
apple:getAuthUrlPublicTrả về Apple authorize URL (response_mode: form_post)
apple:redirectPublicCallback nhận POST form từ Apple (code + user)

Thành phần client

Thành phầnMô tả
AppleButtonNút "Sign in with Apple" theo Apple design guidelines
OptionsForm cấu hình Apple auth trong Settings → Authentication

Dependencies

PackageVai trò
openid-clientOIDC client, xử lý discovery và token exchange
jsonwebtokenDecode và verify JWT id_token
@digiforce-nc/authBase auth framework (peer)
@digiforce-nc/serverServer framework (peer)
@digiforce-nc/clientClient framework (peer)

Mục lục chi tiết