Skip to content

Commit

Permalink
fix: Make ADC + human account work with firebase-admin (#2553)
Browse files Browse the repository at this point in the history
* Make ADC + human account work with firebase-admin

* Update api-request.ts

* fix unit tests

---------

Co-authored-by: Lahiru Maramba <[email protected]>
  • Loading branch information
foxrafa and lahirumaramba authored Jun 19, 2024
1 parent fdde8c3 commit 5f0f253
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/utils/api-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,12 @@ export class AuthorizedHttpClient extends HttpClient {
const authHeader = 'Authorization';
requestCopy.headers[authHeader] = `Bearer ${token}`;

// Fix issue where firebase-admin does not specify quota project that is
// necessary for use when utilizing human account with ADC (RSDF)
if (!requestCopy.headers['x-goog-user-project'] && this.app.options.projectId) {
requestCopy.headers['x-goog-user-project'] = this.app.options.projectId
}

if (!requestCopy.httpAgent && this.app.options.httpAgent) {
requestCopy.httpAgent = this.app.options.httpAgent;
}
Expand Down
1 change: 1 addition & 0 deletions test/unit/app-check/app-check-api-client-internal.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ describe('AppCheckApiClient', () => {
const EXPECTED_HEADERS = {
'Authorization': 'Bearer mock-token',
'X-Firebase-Client': `fire-admin-node/${getSdkVersion()}`,
'x-goog-user-project': 'test-project',
};

const noProjectId = 'Failed to determine project ID. Initialize the SDK with service '
Expand Down
3 changes: 2 additions & 1 deletion test/unit/functions/functions-api-client-internal.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ describe('FunctionsApiClient', () => {

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

const noProjectId = 'Failed to determine project ID. Initialize the SDK with service '
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ describe('MachineLearningApiClient', () => {
const EXPECTED_HEADERS = {
'Authorization': 'Bearer mock-token',
'X-Firebase-Client': `fire-admin-node/${getSdkVersion()}`,
'x-goog-user-project': 'test-project',
};
const noProjectId = 'Failed to determine project ID. Initialize the SDK with service '
+ 'account credentials, or set project ID as an app option. Alternatively, set the '
Expand Down
1 change: 1 addition & 0 deletions test/unit/remote-config/remote-config-api-client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ describe('RemoteConfigApiClient', () => {
'Authorization': 'Bearer mock-token',
'X-Firebase-Client': `fire-admin-node/${getSdkVersion()}`,
'Accept-Encoding': 'gzip',
'x-goog-user-project': 'test-project',
};

const VERSION_INFO: Version = {
Expand Down
1 change: 1 addition & 0 deletions test/unit/security-rules/security-rules-api-client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ describe('SecurityRulesApiClient', () => {
const EXPECTED_HEADERS = {
'Authorization': 'Bearer mock-token',
'X-Firebase-Client': `fire-admin-node/${getSdkVersion()}`,
'x-goog-user-project': 'test-project',
};
const noProjectId = 'Failed to determine project ID. Initialize the SDK with service '
+ 'account credentials, or set project ID as an app option. Alternatively, set the '
Expand Down

0 comments on commit 5f0f253

Please sign in to comment.