Skip to content

Commit ecf0637

Browse files
committed
Pass API Key as request param for Regional Auth requests
1 parent 1aa8468 commit ecf0637

File tree

7 files changed

+22
-16
lines changed

7 files changed

+22
-16
lines changed

packages/auth/src/api/authentication/exchange_token.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ describe('api/authentication/exchange_token', () => {
3737
let regionalAuth: TestAuth;
3838
const request = {
3939
parent: 'test-parent',
40-
token: 'custom-token'
40+
// eslint-disable-next-line camelcase
41+
id_token: 'custom-token'
4142
};
4243

4344
beforeEach(async () => {
@@ -52,6 +53,7 @@ describe('api/authentication/exchange_token', () => {
5253
const mock = mockRegionalEndpointWithParent(
5354
RegionalEndpoint.EXCHANGE_TOKEN,
5455
'test-parent',
56+
'test-api-key',
5557
{ accessToken: 'outbound-token', expiresIn: '1000' }
5658
);
5759

@@ -60,7 +62,8 @@ describe('api/authentication/exchange_token', () => {
6062
expect(response.expiresIn).equal('1000');
6163
expect(mock.calls[0].request).to.eql({
6264
parent: 'test-parent',
63-
token: 'custom-token'
65+
// eslint-disable-next-line camelcase
66+
id_token: 'custom-token'
6467
});
6568
expect(mock.calls[0].method).to.eq('POST');
6669
expect(mock.calls[0].headers!.get(HttpHeader.CONTENT_TYPE)).to.eq(
@@ -79,6 +82,7 @@ describe('api/authentication/exchange_token', () => {
7982
const mock = mockRegionalEndpointWithParent(
8083
RegionalEndpoint.EXCHANGE_TOKEN,
8184
'test-parent',
85+
'test-api-key',
8286
{
8387
error: {
8488
code: 400,

packages/auth/src/api/authentication/exchange_token.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { Auth } from '../../model/public_types';
2323

2424
export interface ExchangeTokenRequest {
2525
parent: string;
26-
token: string;
26+
id_token: string;
2727
}
2828

2929
export interface ExchangeTokenResponse {

packages/auth/src/api/index.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,7 @@ describe('api/_performRegionalApiRequest', () => {
652652
const mock = mockRegionalEndpointWithParent(
653653
RegionalEndpoint.EXCHANGE_TOKEN,
654654
'test-parent',
655+
'test-api-key',
655656
serverResponse
656657
);
657658
const response = await _performRegionalApiRequest<
@@ -689,6 +690,7 @@ describe('api/_performRegionalApiRequest', () => {
689690
const mock = mockRegionalEndpointWithParent(
690691
RegionalEndpoint.EXCHANGE_TOKEN,
691692
'test-parent',
693+
'test-api-key',
692694
serverResponse
693695
);
694696
await _performRegionalApiRequest<typeof request, typeof serverResponse>(

packages/auth/src/api/index.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -168,17 +168,10 @@ async function performApiRequest<T, V>(
168168
}
169169
}
170170

171-
let queryParamString: string;
172-
if (isRegionalAuthInitialized(auth)) {
173-
queryParamString = querystring({
174-
...params
175-
}).slice(1);
176-
} else {
177-
queryParamString = querystring({
171+
const queryParamString = querystring({
178172
key: auth.config.apiKey,
179173
...params
180174
}).slice(1);
181-
}
182175

183176
const headers = await (auth as AuthInternal)._getAdditionalHeaders();
184177
headers[HttpHeader.CONTENT_TYPE] = 'application/json';

packages/auth/src/core/strategies/exchange_token.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ describe('core/strategies/exchangeToken', () => {
5252
const mock = mockRegionalEndpointWithParent(
5353
RegionalEndpoint.EXCHANGE_TOKEN,
5454
'projects/test-project-id/locations/us/tenants/tenant-1/idpConfigs/idp-config',
55+
'test-api-key',
5556
{ accessToken: 'outbound-token', expiresIn: 10 }
5657
);
5758

@@ -64,7 +65,8 @@ describe('core/strategies/exchangeToken', () => {
6465
expect(mock.calls[0].request).to.eql({
6566
parent:
6667
'projects/test-project-id/locations/us/tenants/tenant-1/idpConfigs/idp-config',
67-
token: 'custom-token'
68+
// eslint-disable-next-line camelcase
69+
id_token: 'custom-token'
6870
});
6971
expect(mock.calls[0].method).to.eq('POST');
7072
expect(mock.calls[0].headers!.get(HttpHeader.CONTENT_TYPE)).to.eq(
@@ -87,6 +89,7 @@ describe('core/strategies/exchangeToken', () => {
8789
const mock = mockRegionalEndpointWithParent(
8890
RegionalEndpoint.EXCHANGE_TOKEN,
8991
'projects/test-project-id/locations/us/tenants/tenant-1/idpConfigs/idp-config',
92+
'test-api-key',
9093
{
9194
error: {
9295
code: 400,
@@ -107,7 +110,8 @@ describe('core/strategies/exchangeToken', () => {
107110
expect(mock.calls[0].request).to.eql({
108111
parent:
109112
'projects/test-project-id/locations/us/tenants/tenant-1/idpConfigs/idp-config',
110-
token: 'custom-token'
113+
// eslint-disable-next-line camelcase
114+
id_token: 'custom-token'
111115
});
112116
expect(mock.calls[0].method).to.eq('POST');
113117
expect(mock.calls[0].headers!.get(HttpHeader.CONTENT_TYPE)).to.eq(

packages/auth/src/core/strategies/exhange_token.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ export async function exchangeToken(
5252
const authInternal = _castAuth(auth);
5353
const token = await getToken(authInternal, {
5454
parent: buildParent(auth, idpConfigId),
55-
token: customToken
55+
// eslint-disable-next-line camelcase
56+
id_token: customToken
5657
});
5758
if (token) {
5859
await authInternal._updateFirebaseToken({

packages/auth/test/helpers/api/helper.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,12 @@ export function mockEndpointWithParams(
5959
export function mockRegionalEndpointWithParent(
6060
endpoint: RegionalEndpoint,
6161
parent: string,
62+
key: string,
6263
response: object,
6364
status = 200
6465
): Route {
65-
const url = `${TEST_SCHEME}://${TEST_HOST}${parent}${endpoint}`;
66-
console.log('here ', url);
66+
let url = `${TEST_SCHEME}://${TEST_HOST}${parent}${endpoint}`;
67+
url += "?key=";
68+
url += key;
6769
return mock(url, response, status);
6870
}

0 commit comments

Comments
 (0)