@@ -26,6 +26,7 @@ import url = require('url');
26
26
import { EventEmitter } from 'events' ;
27
27
import { Readable } from 'stream' ;
28
28
import * as zlibmod from 'zlib' ;
29
+ import { ApplicationDefaultCredential } from '../app/credential-internal' ;
29
30
import { getMetricsHeader } from '../utils/index' ;
30
31
31
32
/** Http method type definition. */
@@ -1077,10 +1078,13 @@ export class AuthorizedHttpClient extends HttpClient {
1077
1078
const authHeader = 'Authorization' ;
1078
1079
requestCopy . headers [ authHeader ] = `Bearer ${ token } ` ;
1079
1080
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 ;
1084
1088
}
1085
1089
1086
1090
if ( ! requestCopy . httpAgent && this . app . options . httpAgent ) {
@@ -1112,6 +1116,15 @@ export class AuthorizedHttp2Client extends Http2Client {
1112
1116
const authHeader = 'Authorization' ;
1113
1117
requestCopy . headers [ authHeader ] = `Bearer ${ token } ` ;
1114
1118
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
+
1115
1128
requestCopy . headers [ 'X-Goog-Api-Client' ] = getMetricsHeader ( )
1116
1129
1117
1130
return super . send ( requestCopy ) ;
0 commit comments