Skip to content

Commit 5f0f253

Browse files
fix: Make ADC + human account work with firebase-admin (#2553)
* Make ADC + human account work with firebase-admin * Update api-request.ts * fix unit tests --------- Co-authored-by: Lahiru Maramba <[email protected]>
1 parent fdde8c3 commit 5f0f253

File tree

6 files changed

+12
-1
lines changed

6 files changed

+12
-1
lines changed

src/utils/api-request.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,12 @@ export class AuthorizedHttpClient extends HttpClient {
818818
const authHeader = 'Authorization';
819819
requestCopy.headers[authHeader] = `Bearer ${token}`;
820820

821+
// Fix issue where firebase-admin does not specify quota project that is
822+
// necessary for use when utilizing human account with ADC (RSDF)
823+
if (!requestCopy.headers['x-goog-user-project'] && this.app.options.projectId) {
824+
requestCopy.headers['x-goog-user-project'] = this.app.options.projectId
825+
}
826+
821827
if (!requestCopy.httpAgent && this.app.options.httpAgent) {
822828
requestCopy.httpAgent = this.app.options.httpAgent;
823829
}

test/unit/app-check/app-check-api-client-internal.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ describe('AppCheckApiClient', () => {
4545
const EXPECTED_HEADERS = {
4646
'Authorization': 'Bearer mock-token',
4747
'X-Firebase-Client': `fire-admin-node/${getSdkVersion()}`,
48+
'x-goog-user-project': 'test-project',
4849
};
4950

5051
const noProjectId = 'Failed to determine project ID. Initialize the SDK with service '

test/unit/functions/functions-api-client-internal.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ describe('FunctionsApiClient', () => {
4444

4545
const EXPECTED_HEADERS = {
4646
'X-Firebase-Client': `fire-admin-node/${getSdkVersion()}`,
47-
'Authorization': 'Bearer mock-token'
47+
'Authorization': 'Bearer mock-token',
48+
'x-goog-user-project': 'test-project',
4849
};
4950

5051
const noProjectId = 'Failed to determine project ID. Initialize the SDK with service '

test/unit/machine-learning/machine-learning-api-client.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ describe('MachineLearningApiClient', () => {
117117
const EXPECTED_HEADERS = {
118118
'Authorization': 'Bearer mock-token',
119119
'X-Firebase-Client': `fire-admin-node/${getSdkVersion()}`,
120+
'x-goog-user-project': 'test-project',
120121
};
121122
const noProjectId = 'Failed to determine project ID. Initialize the SDK with service '
122123
+ 'account credentials, or set project ID as an app option. Alternatively, set the '

test/unit/remote-config/remote-config-api-client.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ describe('RemoteConfigApiClient', () => {
5757
'Authorization': 'Bearer mock-token',
5858
'X-Firebase-Client': `fire-admin-node/${getSdkVersion()}`,
5959
'Accept-Encoding': 'gzip',
60+
'x-goog-user-project': 'test-project',
6061
};
6162

6263
const VERSION_INFO: Version = {

test/unit/security-rules/security-rules-api-client.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ describe('SecurityRulesApiClient', () => {
4444
const EXPECTED_HEADERS = {
4545
'Authorization': 'Bearer mock-token',
4646
'X-Firebase-Client': `fire-admin-node/${getSdkVersion()}`,
47+
'x-goog-user-project': 'test-project',
4748
};
4849
const noProjectId = 'Failed to determine project ID. Initialize the SDK with service '
4950
+ 'account credentials, or set project ID as an app option. Alternatively, set the '

0 commit comments

Comments
 (0)