Skip to content

Commit 8a4312b

Browse files
authored
feat: add token verifier to auth (#10)
1 parent 29ae3cd commit 8a4312b

File tree

17 files changed

+1478
-52
lines changed

17 files changed

+1478
-52
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ jobs:
256256
- name: Checkout custom firebase-tools
257257
uses: actions/checkout@v4
258258
with:
259-
repository: invertase/firebase-functions
259+
repository: invertase/firebase-tools
260260
ref: '@invertase/dart'
261261
path: custom-firebase-tools
262262

example/basic/firebase.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
"functions": {
1111
"port": 5001
1212
},
13+
"auth": {
14+
"port": 9099
15+
},
1316
"pubsub": {
1417
"port": 8085
1518
},

example/basic/lib/main.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,9 @@ void main(List<String> args) {
374374
);
375375

376376
// Before email sent - runs before password reset or sign-in emails
377+
// NOTE: The Auth emulator only supports beforeCreate and beforeSignIn.
378+
// This function is included for manifest snapshot testing but cannot be
379+
// tested with the emulator.
377380
firebase.identity.beforeEmailSent(
378381
(AuthBlockingEvent event) async {
379382
print('Before email sent:');
@@ -393,6 +396,9 @@ void main(List<String> args) {
393396
);
394397

395398
// Before SMS sent - runs before MFA or sign-in SMS messages
399+
// NOTE: The Auth emulator only supports beforeCreate and beforeSignIn.
400+
// This function is included for manifest snapshot testing but cannot be
401+
// tested with the emulator.
396402
firebase.identity.beforeSmsSent(
397403
(AuthBlockingEvent event) async {
398404
print('Before SMS sent:');

example/basic/pubspec.lock

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ packages:
3333
url: "https://pub.dev"
3434
source: hosted
3535
version: "6.4.1"
36+
archive:
37+
dependency: transitive
38+
description:
39+
name: archive
40+
sha256: "2fde1607386ab523f7a36bb3e7edb43bd58e6edaf2ffb29d8a6d578b297fdbbd"
41+
url: "https://pub.dev"
42+
source: hosted
43+
version: "4.0.7"
3644
args:
3745
dependency: transitive
3846
description:
@@ -41,6 +49,14 @@ packages:
4149
url: "https://pub.dev"
4250
source: hosted
4351
version: "2.7.0"
52+
asn1lib:
53+
dependency: transitive
54+
description:
55+
name: asn1lib
56+
sha256: "9a8f69025044eb466b9b60ef3bc3ac99b4dc6c158ae9c56d25eeccf5bc56d024"
57+
url: "https://pub.dev"
58+
source: hosted
59+
version: "1.6.5"
4460
async:
4561
dependency: transitive
4662
description:
@@ -169,6 +185,14 @@ packages:
169185
url: "https://pub.dev"
170186
source: hosted
171187
version: "3.0.7"
188+
crypto_keys:
189+
dependency: transitive
190+
description:
191+
name: crypto_keys
192+
sha256: acc19abf34623d990a0e8aec69463d74a824c31f137128f42e2810befc509ad0
193+
url: "https://pub.dev"
194+
source: hosted
195+
version: "0.3.0+1"
172196
dart_firebase_admin:
173197
dependency: transitive
174198
description:
@@ -201,6 +225,14 @@ packages:
201225
url: "https://pub.dev"
202226
source: hosted
203227
version: "0.3.1"
228+
ffi:
229+
dependency: transitive
230+
description:
231+
name: ffi
232+
sha256: d07d37192dbf97461359c1518788f203b0c9102cfd2c35a716b823741219542c
233+
url: "https://pub.dev"
234+
source: hosted
235+
version: "2.1.5"
204236
file:
205237
dependency: transitive
206238
description:
@@ -328,6 +360,14 @@ packages:
328360
url: "https://pub.dev"
329361
source: hosted
330362
version: "1.0.5"
363+
jose:
364+
dependency: transitive
365+
description:
366+
name: jose
367+
sha256: bd8dd0bee653a78be16f5e2c0387117906f8f5171f7dcc29e3246b6c7cb73918
368+
url: "https://pub.dev"
369+
source: hosted
370+
version: "0.3.5"
331371
js:
332372
dependency: transitive
333373
description:
@@ -416,6 +456,14 @@ packages:
416456
url: "https://pub.dev"
417457
source: hosted
418458
version: "1.5.2"
459+
posix:
460+
dependency: transitive
461+
description:
462+
name: posix
463+
sha256: "6323a5b0fa688b6a010df4905a56b00181479e6d10534cecfecede2aa55add61"
464+
url: "https://pub.dev"
465+
source: hosted
466+
version: "6.0.3"
419467
protobuf:
420468
dependency: transitive
421469
description:
@@ -440,6 +488,14 @@ packages:
440488
url: "https://pub.dev"
441489
source: hosted
442490
version: "1.5.0"
491+
quiver:
492+
dependency: transitive
493+
description:
494+
name: quiver
495+
sha256: ea0b925899e64ecdfbf9c7becb60d5b50e706ade44a85b2363be2a22d88117d2
496+
url: "https://pub.dev"
497+
source: hosted
498+
version: "3.2.2"
443499
shelf:
444500
dependency: "direct main"
445501
description:
@@ -568,6 +624,14 @@ packages:
568624
url: "https://pub.dev"
569625
source: hosted
570626
version: "3.0.3"
627+
x509:
628+
dependency: transitive
629+
description:
630+
name: x509
631+
sha256: cbd1a63846884afd273cda247b0365284c8d85a365ca98e110413f93d105b935
632+
url: "https://pub.dev"
633+
source: hosted
634+
version: "0.2.4+3"
571635
yaml:
572636
dependency: transitive
573637
description:

example/with_options/pubspec.lock

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ packages:
3333
url: "https://pub.dev"
3434
source: hosted
3535
version: "6.4.1"
36+
archive:
37+
dependency: transitive
38+
description:
39+
name: archive
40+
sha256: "2fde1607386ab523f7a36bb3e7edb43bd58e6edaf2ffb29d8a6d578b297fdbbd"
41+
url: "https://pub.dev"
42+
source: hosted
43+
version: "4.0.7"
3644
args:
3745
dependency: transitive
3846
description:
@@ -41,6 +49,14 @@ packages:
4149
url: "https://pub.dev"
4250
source: hosted
4351
version: "2.7.0"
52+
asn1lib:
53+
dependency: transitive
54+
description:
55+
name: asn1lib
56+
sha256: "9a8f69025044eb466b9b60ef3bc3ac99b4dc6c158ae9c56d25eeccf5bc56d024"
57+
url: "https://pub.dev"
58+
source: hosted
59+
version: "1.6.5"
4460
async:
4561
dependency: transitive
4662
description:
@@ -169,6 +185,14 @@ packages:
169185
url: "https://pub.dev"
170186
source: hosted
171187
version: "3.0.7"
188+
crypto_keys:
189+
dependency: transitive
190+
description:
191+
name: crypto_keys
192+
sha256: acc19abf34623d990a0e8aec69463d74a824c31f137128f42e2810befc509ad0
193+
url: "https://pub.dev"
194+
source: hosted
195+
version: "0.3.0+1"
172196
dart_firebase_admin:
173197
dependency: transitive
174198
description:
@@ -201,6 +225,14 @@ packages:
201225
url: "https://pub.dev"
202226
source: hosted
203227
version: "0.3.1"
228+
ffi:
229+
dependency: transitive
230+
description:
231+
name: ffi
232+
sha256: d07d37192dbf97461359c1518788f203b0c9102cfd2c35a716b823741219542c
233+
url: "https://pub.dev"
234+
source: hosted
235+
version: "2.1.5"
204236
file:
205237
dependency: transitive
206238
description:
@@ -328,6 +360,14 @@ packages:
328360
url: "https://pub.dev"
329361
source: hosted
330362
version: "1.0.5"
363+
jose:
364+
dependency: transitive
365+
description:
366+
name: jose
367+
sha256: bd8dd0bee653a78be16f5e2c0387117906f8f5171f7dcc29e3246b6c7cb73918
368+
url: "https://pub.dev"
369+
source: hosted
370+
version: "0.3.5"
331371
js:
332372
dependency: transitive
333373
description:
@@ -408,6 +448,14 @@ packages:
408448
url: "https://pub.dev"
409449
source: hosted
410450
version: "1.5.2"
451+
posix:
452+
dependency: transitive
453+
description:
454+
name: posix
455+
sha256: "6323a5b0fa688b6a010df4905a56b00181479e6d10534cecfecede2aa55add61"
456+
url: "https://pub.dev"
457+
source: hosted
458+
version: "6.0.3"
411459
protobuf:
412460
dependency: transitive
413461
description:
@@ -432,6 +480,14 @@ packages:
432480
url: "https://pub.dev"
433481
source: hosted
434482
version: "1.5.0"
483+
quiver:
484+
dependency: transitive
485+
description:
486+
name: quiver
487+
sha256: ea0b925899e64ecdfbf9c7becb60d5b50e706ade44a85b2363be2a22d88117d2
488+
url: "https://pub.dev"
489+
source: hosted
490+
version: "3.2.2"
435491
shelf:
436492
dependency: transitive
437493
description:
@@ -560,6 +616,14 @@ packages:
560616
url: "https://pub.dev"
561617
source: hosted
562618
version: "3.0.3"
619+
x509:
620+
dependency: transitive
621+
description:
622+
name: x509
623+
sha256: cbd1a63846884afd273cda247b0365284c8d85a365ca98e110413f93d105b935
624+
url: "https://pub.dev"
625+
source: hosted
626+
version: "0.2.4+3"
563627
yaml:
564628
dependency: transitive
565629
description:

lib/src/identity/auth_user_record.dart

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,18 @@ class AuthUserInfo {
1313
});
1414

1515
factory AuthUserInfo.fromJson(Map<String, dynamic> json) => AuthUserInfo(
16-
uid: json['uid'] as String,
17-
displayName: json['displayName'] as String? ?? '',
16+
uid: json['uid'] as String? ?? json['raw_id'] as String? ?? '',
17+
displayName: json['displayName'] as String? ??
18+
json['display_name'] as String? ??
19+
'',
1820
email: json['email'] as String? ?? '',
19-
photoURL: json['photoURL'] as String? ?? '',
20-
providerId: json['providerId'] as String,
21-
phoneNumber: json['phoneNumber'] as String?,
21+
photoURL:
22+
json['photoURL'] as String? ?? json['photo_url'] as String? ?? '',
23+
providerId: json['providerId'] as String? ??
24+
json['provider_id'] as String? ??
25+
'',
26+
phoneNumber:
27+
json['phoneNumber'] as String? ?? json['phone_number'] as String?,
2228
);
2329

2430
/// The user identifier for the linked provider.
@@ -73,6 +79,12 @@ class AuthUserMetadata {
7379
return DateTime.fromMillisecondsSinceEpoch(value);
7480
}
7581
if (value is String) {
82+
// Try parsing as integer first (milliseconds since epoch)
83+
final asInt = int.tryParse(value);
84+
if (asInt != null) {
85+
return DateTime.fromMillisecondsSinceEpoch(asInt);
86+
}
87+
// Otherwise parse as ISO string
7688
return DateTime.parse(value);
7789
}
7890
throw ArgumentError('Invalid date format: $value');

0 commit comments

Comments
 (0)