@@ -28,6 +28,7 @@ interface TokenListener {
2828}
2929
3030export class AuthInterop implements FirebaseAuthInternal {
31+ private readonly TOKEN_EXPIRATION_BUFFER = 30_000 ;
3132 private readonly internalListeners : Map < TokenListener , Unsubscribe > =
3233 new Map ( ) ;
3334
@@ -51,6 +52,26 @@ export class AuthInterop implements FirebaseAuthInternal {
5152 return { accessToken } ;
5253 }
5354
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+
5475 addAuthTokenListener ( listener : TokenListener ) : void {
5576 this . assertAuthConfigured ( ) ;
5677 if ( this . internalListeners . has ( listener ) ) {
@@ -85,6 +106,10 @@ export class AuthInterop implements FirebaseAuthInternal {
85106 ) ;
86107 }
87108
109+ private assertRegionalAuthConfigured ( ) : void {
110+ _assert ( this . auth . tenantConfig , AuthErrorCode . OPERATION_NOT_ALLOWED ) ;
111+ }
112+
88113 private updateProactiveRefresh ( ) : void {
89114 if ( this . internalListeners . size > 0 ) {
90115 this . auth . _startProactiveRefresh ( ) ;
0 commit comments