Skip to content

Commit

Permalink
chore: Add X-Goog-Api-Client metric header to Auth and FCM requests (
Browse files Browse the repository at this point in the history
…#2738)

* [chore] Add `X-Goog-Api-Client` metric header to Auth and FCM requests

* trigger integration tests
  • Loading branch information
jonathanedey authored Oct 23, 2024
1 parent 0d21e94 commit 4818109
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/auth/auth-api-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ import {
import { ProjectConfig, ProjectConfigServerResponse, UpdateProjectConfigRequest } from './project-config';

/** Firebase Auth request header. */
const FIREBASE_AUTH_HEADER = {
const FIREBASE_AUTH_HEADERS = {
'X-Client-Version': `Node/Admin/${utils.getSdkVersion()}`,
'X-Goog-Api-Client': `gl-node/${process.versions.node} fire-admin/${utils.getSdkVersion()}`
};
/** Firebase Auth request timeout duration in milliseconds. */
const FIREBASE_AUTH_TIMEOUT = 25000;
Expand Down Expand Up @@ -1919,7 +1920,7 @@ export abstract class AbstractAuthRequestHandler {
const req: HttpRequestConfig = {
method: apiSettings.getHttpMethod(),
url,
headers: FIREBASE_AUTH_HEADER,
headers: FIREBASE_AUTH_HEADERS,
data: requestData,
timeout: FIREBASE_AUTH_TIMEOUT,
};
Expand Down
2 changes: 2 additions & 0 deletions src/messaging/messaging-api-request-internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ const FIREBASE_MESSAGING_BATCH_URL = 'https://fcm.googleapis.com/batch';
const FIREBASE_MESSAGING_HTTP_METHOD: HttpMethod = 'POST';
const FIREBASE_MESSAGING_HEADERS = {
'X-Firebase-Client': `fire-admin-node/${getSdkVersion()}`,
'X-Goog-Api-Client': `gl-node/${process.versions.node} fire-admin/${getSdkVersion()}`
};
const LEGACY_FIREBASE_MESSAGING_HEADERS = {
'X-Firebase-Client': `fire-admin-node/${getSdkVersion()}`,
'X-Goog-Api-Client': `gl-node/${process.versions.node} fire-admin/${getSdkVersion()}`,
'access_token_auth': 'true',
};

Expand Down
2 changes: 2 additions & 0 deletions test/unit/auth/auth-api-request.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -863,10 +863,12 @@ AUTH_REQUEST_HANDLER_TESTS.forEach((handler) => {
const mockAccessToken: string = utils.generateRandomAccessToken();
const expectedHeaders: {[key: string]: string} = {
'X-Client-Version': `Node/Admin/${getSdkVersion()}`,
'X-Goog-Api-Client': `gl-node/${process.versions.node} fire-admin/${getSdkVersion()}`,
'Authorization': 'Bearer ' + mockAccessToken,
};
const expectedHeadersEmulator: {[key: string]: string} = {
'X-Client-Version': `Node/Admin/${getSdkVersion()}`,
'X-Goog-Api-Client': `gl-node/${process.versions.node} fire-admin/${getSdkVersion()}`,
'Authorization': 'Bearer owner',
};
const callParams = (path: string, method: any, data: any): HttpRequestConfig => {
Expand Down
1 change: 1 addition & 0 deletions test/unit/messaging/messaging.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ describe('Messaging', () => {
const expectedHeaders = {
'Authorization': 'Bearer ' + mockAccessToken,
'X-Firebase-Client': `fire-admin-node/${getSdkVersion()}`,
'X-Goog-Api-Client': `gl-node/${process.versions.node} fire-admin/${getSdkVersion()}`,
'access_token_auth': 'true',
};
const emptyResponse = utils.responseFrom({});
Expand Down

0 comments on commit 4818109

Please sign in to comment.