Description
Is your feature request related to a problem? Please describe.
We have a need to instantiate multiple instances of firebase admin to access multiple projects at the same time. This works nicely in production using:
const serviceAccountObject = JSON.parse(serviceAccountString)
const app1 = initializeApp({
projectId: projectId,
credential: cert(serviceAccountObject),
databaseURL: databaseUrl,
storageBucket: storageBucket
}, 'myNamedApp1')
However, it seems to be impossible to supply the impersonated service account json from local ADC login (obtained using gcloud auth application-default login --impersonate-service-account [email protected]
) as ImpersonatedServiceAccountCredential
is not exported.
We rolled our own, but it fails as isApplicationDefault
uses instanceof to do the checking.
Describe the solution you'd like
Add a way to initialize from ADC logins manually: add a method (like refreshToken
and cert
) to src/app/credential-factory.ts
that takes impersonatedServiceAccountPathOrObject
etc as parameter.
const globalImpersonatedServiceAccountCreds: { [key: string]: ImpersonatedServiceAccountCredential } = {};
export function impersonatedServiceAccount(impersonatedServiceAccountPathOrObject: string | object, httpAgent?: Agent): Credential {
const stringifiedImpersonatedServiceAccount = JSON.stringify(impersonatedServiceAccountPathOrObject);
if (!(stringifiedImpersonatedServiceAccount in globalImpersonatedServiceAccountCreds)) {
globalImpersonatedServiceAccountCreds[stringifiedImpersonatedServiceAccount] = new ImpersonatedServiceAccountCredential(
impersonatedServiceAccountPathOrObject, httpAgent);
}
return globalImpersonatedServiceAccountCreds[stringifiedImpersonatedServiceAccount];
}