Refactor: Consolidate JWKS fetching and expose a unified JWT verifier for downstream SDKs

Đang mở
#299 9 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 6 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
35/100
Loại issue
Tái cấu trúc
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Ít trao đổi
Công nghệ
dart

Hướng nghiên cứu

Bắt đầu bằng cách đọc packages/firebase_admin_sdk/lib/src/utils/jwt.dart, đặc biệt là UrlKeyFetcher, JwksFetcher và PublicKeySignatureVerifier, sau đó so sánh các trình xác minh token và firebase_functions/lib/src/identity/token_verifier.dart. Lập bản đồ các khác biệt về cache, clock-skew và xác thực audience trước khi chọn một API dùng chung. Công việc được xem là hoàn tất khi các SDK downstream có thể sử dụng một trình xác minh có thể tái sử dụng mà không cần sao chép việc lấy khóa hoặc xác thực claim.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

keep-open package:firebase_admin_sdk
Background

Across firebase_admin_sdk and downstream consumers like firebase_functions (which depends on firebase_admin_sdk), there are multiple overlapping implementations of JWT signature verification, JWKS / X.509 certificate fetching, and public key caching.

Currently, firebase_admin_sdk maintains both UrlKeyFetcher (for X.509 PEM certs) and JwksFetcher (for JSON Web Key Sets) in lib/src/utils/jwt.dart.

Current Inconsistencies & Duplication
  1. Inconsistent Key Caching & TTLs:
    • UrlKeyFetcher parses HTTP Cache-Control: max-age headers via string splitting and tracks expiration via DateTime.
    • JwksFetcher ignores HTTP Cache-Control headers entirely, hardcoding a static 6-hour TTL (6 * 60 * 60 * 1000) and tracking expiration via epoch integer comparison.
    • Meanwhile, downstream in firebase_functions, AuthBlockingTokenVerifier hand-rolled a third key fetcher (_getGoogleKeys()) that parses Cache-Control: max-age via regex and defaults to a 1-hour TTL.
  2. Inconsistent Clock Skew and Claim Validation:
    • Neither FirebaseTokenVerifier nor AppCheckTokenVerifier supports clock-skew tolerance on timestamps (iat, exp). However, Auth Blocking events in firebase_functions require a 5-minute clock skew on iat.
    • Audience (aud) claim handling varies: ID token verification assumes String, App Check assumes List, and downstream functions must handle both String and List polymorphically.
  3. Lack of Reusability for Downstream Packages:
    • Because PublicKeySignatureVerifier and JwksFetcher are either marked @internal or lack configuration ergonomics (v3 JWKS endpoints, clock skew, polymorphic audience matching), firebase_functions was forced to duplicate the entire JWT verification stack from scratch.
Proposed Action Items
  • Unify JwksFetcher and UrlKeyFetcher to share standard HTTP Cache-Control: max-age parsing (with a sensible default fallback like 1 hour).
  • Support configurable clock-skew tolerance (e.g., an optional Duration clockSkew parameter) in PublicKeySignatureVerifier and claim validation.
  • Support polymorphic audience (aud) matching (String vs. List<String>).
  • Expose a clean, reusable JWT verification primitive (or align with an upstream foundation like google_cloud_server_auth) so downstream SDKs like firebase_functions can delete their custom verifiers and rely directly on firebase_admin_sdk.
Ngôn ngữ chính
Dart
Star
180
Fork
73
Merge trung bình
5 ngày 8 giờ
Pull request đã merge (30 ngày)
9

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của firebase/firebase-admin-dart

Tất cả issue của firebase/firebase-admin-dart

Issue tương tự

Thêm issue về Dart

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.