@@ -26,14 +26,15 @@ import { ComponentContainer } from '@firebase/component';
2626import { FirebaseAppImpl } from './firebaseApp' ;
2727import { ERROR_FACTORY , AppError } from './errors' ;
2828import { name as packageName , version } from '../package.json' ;
29+ import { base64Decode } from '@firebase/util' ;
2930
3031export class FirebaseServerAppImpl
3132 extends FirebaseAppImpl
32- implements FirebaseServerApp
33- {
33+ implements FirebaseServerApp {
3434 private readonly _serverConfig : FirebaseServerAppSettings ;
3535 private _finalizationRegistry : FinalizationRegistry < object > | null ;
3636 private _refCount : number ;
37+ private _installationsId : string | null ;
3738
3839 constructor (
3940 options : FirebaseOptions | FirebaseAppImpl ,
@@ -67,6 +68,20 @@ export class FirebaseServerAppImpl
6768 ...serverConfig
6869 } ;
6970
71+ // Parse the installationAuthToken if provided.
72+ if ( this . _serverConfig . installationsAuthToken !== undefined ) {
73+ const thirdPart = this . _serverConfig . installationsAuthToken . split ( "." ) [ 1 ] . split ( "." ) [ 0 ] ;
74+ const decodedToken = base64Decode ( thirdPart ) ;
75+ const tokenJSON = JSON . parse ( decodedToken ? decodedToken : "" ) ;
76+ if ( ! decodedToken || ! tokenJSON || tokenJSON . fid === undefined ) {
77+ throw ERROR_FACTORY . create ( AppError . INVALID_SERVER_APP_INSTALLATIONS_AUTH_TOKEN ) ;
78+ } else {
79+ this . _installationsId = tokenJSON . fid ;
80+ }
81+ } else {
82+ this . _installationsId = null ;
83+ }
84+
7085 this . _finalizationRegistry = null ;
7186 if ( typeof FinalizationRegistry !== 'undefined' ) {
7287 this . _finalizationRegistry = new FinalizationRegistry ( ( ) => {
@@ -125,6 +140,20 @@ export class FirebaseServerAppImpl
125140 return this . _serverConfig ;
126141 }
127142
143+ get installationsAuthToken ( ) : string | null {
144+ this . checkDestroyed ( ) ;
145+ if ( this . _serverConfig . installationsAuthToken !== undefined ) {
146+ return this . _serverConfig . installationsAuthToken ;
147+ } else {
148+ return null ;
149+ }
150+ }
151+
152+ get installationsId ( ) : string | null {
153+ this . checkDestroyed ( ) ;
154+ return this . _installationsId ;
155+ }
156+
128157 /**
129158 * This function will throw an Error if the App has already been deleted -
130159 * use before performing API actions on the App.
0 commit comments