From 07a82cf9af132607035b2d0ee1216b018db43a63 Mon Sep 17 00:00:00 2001 From: Kushal Palesha <3357451+kushalpalesha@users.noreply.github.com> Date: Mon, 10 Nov 2025 20:47:36 +0000 Subject: [PATCH 1/5] add authcontxt params to the DatabaseEvent object --- src/v2/providers/database.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/v2/providers/database.ts b/src/v2/providers/database.ts index c85f01172..5c7282f67 100644 --- a/src/v2/providers/database.ts +++ b/src/v2/providers/database.ts @@ -80,6 +80,14 @@ export interface DatabaseEvent> extends Cloud * Only named capture groups will be populated - {key}, {key=*}, {key=**} */ params: Params; + /** + * The type of principal that triggered the event. + */ + authType?: "app_user" | "admin" | "unauthenticated"; + /** + * The unique identifier of the principal. + */ + authId?: string; } /** ReferenceOptions extend EventHandlerOptions with provided ref and optional instance */ From e3f307e7bb724e68b5e48d307c1925a054ffbce8 Mon Sep 17 00:00:00 2001 From: Kushal Palesha <3357451+kushalpalesha@users.noreply.github.com> Date: Thu, 13 Nov 2025 20:26:08 +0000 Subject: [PATCH 2/5] add unittest --- spec/v2/providers/database.spec.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/spec/v2/providers/database.spec.ts b/spec/v2/providers/database.spec.ts index 9eabf61ca..6a9216279 100644 --- a/spec/v2/providers/database.spec.ts +++ b/spec/v2/providers/database.spec.ts @@ -461,6 +461,21 @@ describe("database", () => { await database.onValueWritten("path", () => null)(event); expect(hello).to.equal("world"); }); + + it("should pass auth context into the event", async () => { + const raw = { + ...RAW_RTDB_EVENT, + authId: "uid", + authType: "unauthenticated", + }; + + const func = database.onValueWritten("foo/bar", (event) => { + expect(event.authId).to.equal("uid"); + expect(event.authType).to.equal("unauthenticated"); + }); + + await func(raw as any); + }); }); describe("onValueCreated", () => { From 2683b7a626e721a21ac6b4fb9141e8a07e3512bd Mon Sep 17 00:00:00 2001 From: Kushal Palesha <3357451+kushalpalesha@users.noreply.github.com> Date: Thu, 13 Nov 2025 20:37:02 +0000 Subject: [PATCH 3/5] address review comment --- spec/v2/providers/database.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/v2/providers/database.spec.ts b/spec/v2/providers/database.spec.ts index 6a9216279..4bd2e1407 100644 --- a/spec/v2/providers/database.spec.ts +++ b/spec/v2/providers/database.spec.ts @@ -474,7 +474,7 @@ describe("database", () => { expect(event.authType).to.equal("unauthenticated"); }); - await func(raw as any); + await func(raw); }); }); From 21d2c10c3128c6d51882691f1e1823bcafda4908 Mon Sep 17 00:00:00 2001 From: Kushal Palesha <3357451+kushalpalesha@users.noreply.github.com> Date: Fri, 14 Nov 2025 07:41:07 +0000 Subject: [PATCH 4/5] add authcxt params to RawRTDBCloudEvent and use a type for AuthType values --- spec/v2/providers/database.spec.ts | 8 ++++---- src/v2/providers/database.ts | 17 +++++++++++++++-- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/spec/v2/providers/database.spec.ts b/spec/v2/providers/database.spec.ts index 4bd2e1407..bd0a10b39 100644 --- a/spec/v2/providers/database.spec.ts +++ b/spec/v2/providers/database.spec.ts @@ -42,6 +42,8 @@ const RAW_RTDB_EVENT: database.RawRTDBCloudEvent = { specversion: "1.0", time: "time", type: "type", + authid: "uid", + authtype: "unauthenticated", }; describe("database", () => { @@ -465,13 +467,11 @@ describe("database", () => { it("should pass auth context into the event", async () => { const raw = { ...RAW_RTDB_EVENT, - authId: "uid", - authType: "unauthenticated", }; const func = database.onValueWritten("foo/bar", (event) => { - expect(event.authId).to.equal("uid"); - expect(event.authType).to.equal("unauthenticated"); + expect(event.authid).to.equal("uid"); + expect(event.authtype).to.equal("unauthenticated"); }); await func(raw); diff --git a/src/v2/providers/database.ts b/src/v2/providers/database.ts index 5c7282f67..8fbfccdc7 100644 --- a/src/v2/providers/database.ts +++ b/src/v2/providers/database.ts @@ -63,8 +63,19 @@ export interface RawRTDBCloudEvent extends CloudEvent { instance: string; ref: string; location: string; + authtype: AuthType; + authid?: string; } +/** + * AuthType defines the possible values for the authType field in a Realtime Database event. + * - app_user: an end user of an application.. + * - admin: an admin user of an application. In the context of impersonate endpoints used by the admin SDK, the impersonator. + * - unauthenticated: no credentials were used to authenticate the change that triggered the occurrence. + * - unknown: a general type to capture all other principals not captured in the other auth types. + */ +export type AuthType = "app_user" | "admin" | "unauthenticated" | "unknown"; + /** A CloudEvent that contains a DataSnapshot or a Change */ export interface DatabaseEvent> extends CloudEvent { /** The domain of the database instance */ @@ -83,11 +94,11 @@ export interface DatabaseEvent> extends Cloud /** * The type of principal that triggered the event. */ - authType?: "app_user" | "admin" | "unauthenticated"; + authtype: AuthType /** * The unique identifier of the principal. */ - authId?: string; + authid?: string; } /** ReferenceOptions extend EventHandlerOptions with provided ref and optional instance */ @@ -392,6 +403,8 @@ function makeDatabaseEvent( firebaseDatabaseHost: event.firebasedatabasehost, data: snapshot, params, + authtype: event.authtype, + authid: event.authid }; delete (databaseEvent as any).firebasedatabasehost; return databaseEvent; From 819c5d071498d5757eb817068af5771935868e5d Mon Sep 17 00:00:00 2001 From: Kushal Palesha <3357451+kushalpalesha@users.noreply.github.com> Date: Fri, 14 Nov 2025 07:58:36 +0000 Subject: [PATCH 5/5] fix lint --- src/v2/providers/database.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/v2/providers/database.ts b/src/v2/providers/database.ts index 8fbfccdc7..561b38680 100644 --- a/src/v2/providers/database.ts +++ b/src/v2/providers/database.ts @@ -64,7 +64,7 @@ export interface RawRTDBCloudEvent extends CloudEvent { ref: string; location: string; authtype: AuthType; - authid?: string; + authid?: string; } /** @@ -94,7 +94,7 @@ export interface DatabaseEvent> extends Cloud /** * The type of principal that triggered the event. */ - authtype: AuthType + authtype: AuthType; /** * The unique identifier of the principal. */ @@ -404,7 +404,7 @@ function makeDatabaseEvent( data: snapshot, params, authtype: event.authtype, - authid: event.authid + authid: event.authid, }; delete (databaseEvent as any).firebasedatabasehost; return databaseEvent;