@@ -28,6 +28,7 @@ interface TokenListener {
28
28
}
29
29
30
30
export class AuthInterop implements FirebaseAuthInternal {
31
+ private readonly TOKEN_EXPIRATION_BUFFER = 30_000 ;
31
32
private readonly internalListeners : Map < TokenListener , Unsubscribe > =
32
33
new Map ( ) ;
33
34
@@ -51,6 +52,26 @@ export class AuthInterop implements FirebaseAuthInternal {
51
52
return { accessToken } ;
52
53
}
53
54
55
+ async getFirebaseToken ( ) : Promise < { accessToken : string } | null > {
56
+ this . assertAuthConfigured ( ) ;
57
+ this . assertRegionalAuthConfigured ( ) ;
58
+ if ( ! this . auth . firebaseToken ) {
59
+ return null ;
60
+ }
61
+
62
+ if (
63
+ ! this . auth . firebaseToken . expirationTime ||
64
+ Date . now ( ) >
65
+ this . auth . firebaseToken . expirationTime - this . TOKEN_EXPIRATION_BUFFER
66
+ ) {
67
+ await this . auth . _updateFirebaseToken ( null ) ;
68
+ return null ;
69
+ }
70
+
71
+ const accessToken = await this . auth . firebaseToken . token ;
72
+ return { accessToken } ;
73
+ }
74
+
54
75
addAuthTokenListener ( listener : TokenListener ) : void {
55
76
this . assertAuthConfigured ( ) ;
56
77
if ( this . internalListeners . has ( listener ) ) {
@@ -85,6 +106,10 @@ export class AuthInterop implements FirebaseAuthInternal {
85
106
) ;
86
107
}
87
108
109
+ private assertRegionalAuthConfigured ( ) : void {
110
+ _assert ( this . auth . tenantConfig , AuthErrorCode . OPERATION_NOT_ALLOWED ) ;
111
+ }
112
+
88
113
private updateProactiveRefresh ( ) : void {
89
114
if ( this . internalListeners . size > 0 ) {
90
115
this . auth . _startProactiveRefresh ( ) ;
0 commit comments