@@ -26,6 +26,7 @@ import url = require('url');
2626import { EventEmitter } from 'events' ;
2727import { Readable } from 'stream' ;
2828import * as zlibmod from 'zlib' ;
29+ import { ApplicationDefaultCredential } from '../app/credential-internal' ;
2930import { getMetricsHeader } from '../utils/index' ;
3031
3132/** Http method type definition. */
@@ -1077,10 +1078,13 @@ export class AuthorizedHttpClient extends HttpClient {
10771078 const authHeader = 'Authorization' ;
10781079 requestCopy . headers [ authHeader ] = `Bearer ${ token } ` ;
10791080
1080- // Fix issue where firebase-admin does not specify quota project that is
1081- // necessary for use when utilizing human account with ADC (RSDF)
1082- if ( ! requestCopy . headers [ 'x-goog-user-project' ] && this . app . options . projectId ) {
1083- requestCopy . headers [ 'x-goog-user-project' ] = this . app . options . projectId
1081+ let quotaProjectId : string | undefined ;
1082+ if ( this . app . options . credential instanceof ApplicationDefaultCredential ) {
1083+ quotaProjectId = this . app . options . credential . getQuotaProjectId ( ) ;
1084+ }
1085+ quotaProjectId = process . env . GOOGLE_CLOUD_QUOTA_PROJECT || quotaProjectId ;
1086+ if ( ! requestCopy . headers [ 'x-goog-user-project' ] && validator . isNonEmptyString ( quotaProjectId ) ) {
1087+ requestCopy . headers [ 'x-goog-user-project' ] = quotaProjectId ;
10841088 }
10851089
10861090 if ( ! requestCopy . httpAgent && this . app . options . httpAgent ) {
@@ -1112,6 +1116,15 @@ export class AuthorizedHttp2Client extends Http2Client {
11121116 const authHeader = 'Authorization' ;
11131117 requestCopy . headers [ authHeader ] = `Bearer ${ token } ` ;
11141118
1119+ let quotaProjectId : string | undefined ;
1120+ if ( this . app . options . credential instanceof ApplicationDefaultCredential ) {
1121+ quotaProjectId = this . app . options . credential . getQuotaProjectId ( ) ;
1122+ }
1123+ quotaProjectId = process . env . GOOGLE_CLOUD_QUOTA_PROJECT || quotaProjectId ;
1124+ if ( ! requestCopy . headers [ 'x-goog-user-project' ] && validator . isNonEmptyString ( quotaProjectId ) ) {
1125+ requestCopy . headers [ 'x-goog-user-project' ] = quotaProjectId ;
1126+ }
1127+
11151128 requestCopy . headers [ 'X-Goog-Api-Client' ] = getMetricsHeader ( )
11161129
11171130 return super . send ( requestCopy ) ;
0 commit comments