Skip to content

Commit 2841ebd

Browse files
authored
Fix bug where auth metadata in the auth blocking tokens are assumed to be seconds not miliseconds (#1472)
Auth metadata included in the JWT sent to Auth Blocking functions may include fields `last_sign_in_time` and `creation_time`. Values of these fields are sent as _miliseconds_ since epoch. The SDK incorrectly assumes that they are _seconds_ since epoch. Unfortunately, this information is not publicly documented, but I was able to verify the fix in production. Fixes: #1468
1 parent 93c47e3 commit 2841ebd

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
- Remove HTTP server shutdown message. (#1457)
22
- Add features to task queue functions. (#1423)
33
- Add traces to V2 Firestore trigger logs. (#1440)
4+
- Fix incorrectly parsed timestamps in auth blocking functions. (#1472)

spec/common/providers/identity.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,8 @@ describe("identity", () => {
207207

208208
describe("parseMetadata", () => {
209209
const decodedMetadata = {
210-
last_sign_in_time: 1476235905,
211-
creation_time: 1476136676,
210+
last_sign_in_time: 1476235905000,
211+
creation_time: 1476136676000,
212212
};
213213
const metadata = {
214214
lastSignInTime: new Date(1476235905000).toUTCString(),
@@ -374,8 +374,8 @@ describe("identity", () => {
374374
photo_url: "https://lh3.googleusercontent.com/1234567890/photo.jpg",
375375
tokens_valid_after_time: 1476136676,
376376
metadata: {
377-
last_sign_in_time: 1476235905,
378-
creation_time: 1476136676,
377+
last_sign_in_time: 1476235905000,
378+
creation_time: 1476136676000,
379379
},
380380
custom_claims: {
381381
admin: true,
@@ -632,8 +632,8 @@ describe("identity", () => {
632632
photo_url: "https://lh3.googleusercontent.com/1234567890/photo.jpg",
633633
tokens_valid_after_time: 1476136676,
634634
metadata: {
635-
last_sign_in_time: 1476235905,
636-
creation_time: 1476136676,
635+
last_sign_in_time: 1476235905000,
636+
creation_time: 1476136676000,
637637
},
638638
custom_claims: {
639639
admin: true,

src/common/providers/identity.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -489,10 +489,10 @@ function unsafeDecodeAuthBlockingToken(token: string): DecodedPayload {
489489
*/
490490
export function parseMetadata(metadata: DecodedPayloadUserRecordMetadata): AuthUserMetadata {
491491
const creationTime = metadata?.creation_time
492-
? new Date(metadata.creation_time * 1000).toUTCString()
492+
? new Date(metadata.creation_time).toUTCString()
493493
: null;
494494
const lastSignInTime = metadata?.last_sign_in_time
495-
? new Date(metadata.last_sign_in_time * 1000).toUTCString()
495+
? new Date(metadata.last_sign_in_time).toUTCString()
496496
: null;
497497
return {
498498
creationTime,

0 commit comments

Comments
 (0)