ReferencePlatforms
@gentlemans-stack/auth-firebase
Firebase Auth ID-token providers for @gentlemans-stack/auth's AuthProvider contract. A GCP platform package: only
services and apps import it, never the core (see the platforms zone in .fallowrc.json).
Two providers, each behind its own subpath so a service loads only the SDK it uses. There is no root export.
| Import | Export | Use it when |
|---|---|---|
@gentlemans-stack/auth-firebase/admin | createFirebaseAdminAuthProvider<TLogger, TOwner>({ resolveOwner }) | The service already runs firebase-admin and must cut off disabled or revoked accounts at once. |
@gentlemans-stack/auth-firebase/jwks | createFirebaseJwksAuthProvider({ projectId, jwksUrl? }), FIREBASE_JWKS_URL | Verifying the token is enough and the service should not pull in firebase-admin. |
API
./admin:createFirebaseAdminAuthProvider(config:FirebaseAdminAuthProviderConfig), usingfirebase-admin../jwks:createFirebaseJwksAuthProvider(config:FirebaseJwksAuthProviderConfig), withoutfirebase-admin;FIREBASE_JWKS_URL.
admin: firebase-admin, with revocation
createFirebaseAdminAuthProvider<TLogger, TOwner extends Record<string, unknown>>({
resolveOwner: (token: DecodedIdToken, logger: TLogger) => Promise<TOwner | null>,
}): AuthProvider<{ logger: TLogger }, TOwner & { firebaseAuthID: string }>- Calls
getAuth().verifyIdToken(token, true).checkRevokedalso rejects disabled accounts, at the cost of one Firebase Auth API call per request. - Then
resolveOwner(decodedToken, context.logger)on every request, so role and plan changes apply without a new sign-in. The service owns this (lookup, first-request upsert from the token's profile).null→USER_UNAUTHENTICATED(invalid_token). - Principal:
{ claims: { ...owner, firebaseAuthID: uid }, id: uid, roles: [] }. - Needs a default Firebase app: call
initializeApp(...)fromfirebase-admin/appat service startup.
jwks: no firebase-admin
createFirebaseJwksAuthProvider({ projectId, jwksUrl = FIREBASE_JWKS_URL }): {
verifyToken: (token: string) => Promise<Principal<JwtProfileClaims>>;
}- Wraps
createJwtAuthProviderwith Google's securetoken JWKS: RS256 signature,iss=https://securetoken.google.com/<projectId>,aud=projectId,exp, and a non-emptysub(the uid). - Principal:
{ claims: { email?, name?, picture? }, id: uid, roles: [] }. No owner lookup; wrap it or chain it if the service needs one. - No revocation check: a disabled account keeps working until its ID token expires (up to an hour).
jwksUrlis overridable for tests only.
Testing
pnpm nx test auth-firebase. The admin specs mock firebase-admin/auth with vi.hoisted + vi.mock; the jwks
specs sign real RS256 tokens against a local JWKS server. No real credentials. Guidance: the nested
platforms/gcp/.claude/skills/firebase-auth-tests skill.