Skip to content

Commit c236221

Browse files
authored
[Auth] Remove tenantId field from calls to MFA endpoints (#5522)
* Remove tenantId field from calls to MFA endpoints * Changeset
1 parent 8468d7f commit c236221

File tree

8 files changed

+32
-79
lines changed

8 files changed

+32
-79
lines changed

.changeset/tender-walls-hang.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@firebase/auth": patch
3+
---
4+
5+
Fix wrongly-typed tenantId fields in requests to some endpoints

packages/auth/src/api/account_management/mfa.test.ts

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,7 @@ describe('api/account_management/startEnrollPhoneMfa', () => {
6060

6161
const response = await startEnrollPhoneMfa(auth, request);
6262
expect(response.phoneSessionInfo.sessionInfo).to.eq('session-info');
63-
expect(mock.calls[0].request).to.eql({
64-
tenantId: null,
65-
...request
66-
});
63+
expect(mock.calls[0].request).to.eql(request);
6764
expect(mock.calls[0].method).to.eq('POST');
6865
expect(mock.calls[0].headers!.get(HttpHeader.CONTENT_TYPE)).to.eq(
6966
'application/json'
@@ -94,10 +91,7 @@ describe('api/account_management/startEnrollPhoneMfa', () => {
9491
FirebaseError,
9592
"Firebase: This user's credential isn't valid for this project. This can happen if the user's token has been tampered with, or if the user isn't for the project associated with this API key. (auth/invalid-user-token)."
9693
);
97-
expect(mock.calls[0].request).to.eql({
98-
tenantId: null,
99-
...request
100-
});
94+
expect(mock.calls[0].request).to.eql(request);
10195
});
10296
});
10397

@@ -130,10 +124,7 @@ describe('api/account_management/finalizeEnrollPhoneMfa', () => {
130124
const response = await finalizeEnrollPhoneMfa(auth, request);
131125
expect(response.idToken).to.eq('id-token');
132126
expect(response.refreshToken).to.eq('refresh-token');
133-
expect(mock.calls[0].request).to.eql({
134-
tenantId: null,
135-
...request
136-
});
127+
expect(mock.calls[0].request).to.eql(request);
137128
expect(mock.calls[0].method).to.eq('POST');
138129
expect(mock.calls[0].headers!.get(HttpHeader.CONTENT_TYPE)).to.eq(
139130
'application/json'
@@ -164,10 +155,7 @@ describe('api/account_management/finalizeEnrollPhoneMfa', () => {
164155
FirebaseError,
165156
'Firebase: The verification ID used to create the phone auth credential is invalid. (auth/invalid-verification-id).'
166157
);
167-
expect(mock.calls[0].request).to.eql({
168-
tenantId: null,
169-
...request
170-
});
158+
expect(mock.calls[0].request).to.eql(request);
171159
});
172160
});
173161

@@ -195,10 +183,7 @@ describe('api/account_management/withdrawMfa', () => {
195183
const response = await withdrawMfa(auth, request);
196184
expect(response.idToken).to.eq('id-token');
197185
expect(response.refreshToken).to.eq('refresh-token');
198-
expect(mock.calls[0].request).to.eql({
199-
tenantId: null,
200-
...request
201-
});
186+
expect(mock.calls[0].request).to.eql(request);
202187
expect(mock.calls[0].method).to.eq('POST');
203188
expect(mock.calls[0].headers!.get(HttpHeader.CONTENT_TYPE)).to.eq(
204189
'application/json'
@@ -229,9 +214,6 @@ describe('api/account_management/withdrawMfa', () => {
229214
FirebaseError,
230215
"Firebase: This user's credential isn't valid for this project. This can happen if the user's token has been tampered with, or if the user isn't for the project associated with this API key. (auth/invalid-user-token)."
231216
);
232-
expect(mock.calls[0].request).to.eql({
233-
tenantId: null,
234-
...request
235-
});
217+
expect(mock.calls[0].request).to.eql(request);
236218
});
237219
});

packages/auth/src/api/account_management/mfa.ts

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18-
import { Endpoint, HttpMethod, _performApiRequest } from '../index';
18+
import { Endpoint, HttpMethod, _addTidIfNecessary, _performApiRequest } from '../index';
1919
import { SignInWithPhoneNumberRequest } from '../authentication/sms';
2020
import { FinalizeMfaResponse } from '../authentication/mfa';
2121
import { AuthInternal } from '../../model/auth';
@@ -47,7 +47,7 @@ export interface StartPhoneMfaEnrollmentRequest {
4747
phoneNumber: string;
4848
recaptchaToken: string;
4949
};
50-
tenantId: string | null;
50+
tenantId?: string;
5151
}
5252

5353
export interface StartPhoneMfaEnrollmentResponse {
@@ -58,59 +58,50 @@ export interface StartPhoneMfaEnrollmentResponse {
5858

5959
export function startEnrollPhoneMfa(
6060
auth: AuthInternal,
61-
request: Omit<StartPhoneMfaEnrollmentRequest, 'tenantId'>
61+
request: StartPhoneMfaEnrollmentRequest
6262
): Promise<StartPhoneMfaEnrollmentResponse> {
6363
return _performApiRequest<
6464
StartPhoneMfaEnrollmentRequest,
6565
StartPhoneMfaEnrollmentResponse
66-
>(auth, HttpMethod.POST, Endpoint.START_PHONE_MFA_ENROLLMENT, {
67-
tenantId: auth.tenantId,
68-
...request
69-
});
66+
>(auth, HttpMethod.POST, Endpoint.START_PHONE_MFA_ENROLLMENT, _addTidIfNecessary(auth, request));
7067
}
7168

7269
export interface FinalizePhoneMfaEnrollmentRequest {
7370
idToken: string;
7471
phoneVerificationInfo: SignInWithPhoneNumberRequest;
7572
displayName?: string | null;
76-
tenantId: string | null;
73+
tenantId?: string;
7774
}
7875

7976
export interface FinalizePhoneMfaEnrollmentResponse
8077
extends FinalizeMfaResponse {}
8178

8279
export function finalizeEnrollPhoneMfa(
8380
auth: AuthInternal,
84-
request: Omit<FinalizePhoneMfaEnrollmentRequest, 'tenantId'>
81+
request: FinalizePhoneMfaEnrollmentRequest
8582
): Promise<FinalizePhoneMfaEnrollmentResponse> {
8683
return _performApiRequest<
8784
FinalizePhoneMfaEnrollmentRequest,
8885
FinalizePhoneMfaEnrollmentResponse
89-
>(auth, HttpMethod.POST, Endpoint.FINALIZE_PHONE_MFA_ENROLLMENT, {
90-
tenantId: auth.tenantId,
91-
...request
92-
});
86+
>(auth, HttpMethod.POST, Endpoint.FINALIZE_PHONE_MFA_ENROLLMENT, _addTidIfNecessary(auth, request));
9387
}
9488

9589
export interface WithdrawMfaRequest {
9690
idToken: string;
9791
mfaEnrollmentId: string;
98-
tenantId: string | null;
92+
tenantId?: string;
9993
}
10094

10195
export interface WithdrawMfaResponse extends FinalizeMfaResponse {}
10296

10397
export function withdrawMfa(
10498
auth: AuthInternal,
105-
request: Omit<WithdrawMfaRequest, 'tenantId'>
99+
request: WithdrawMfaRequest
106100
): Promise<WithdrawMfaResponse> {
107101
return _performApiRequest<WithdrawMfaRequest, WithdrawMfaResponse>(
108102
auth,
109103
HttpMethod.POST,
110104
Endpoint.WITHDRAW_MFA,
111-
{
112-
tenantId: auth.tenantId,
113-
...request
114-
}
105+
_addTidIfNecessary(auth, request)
115106
);
116107
}

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

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,7 @@ describe('api/authentication/startSignInPhoneMfa', () => {
5656

5757
const response = await startSignInPhoneMfa(auth, request);
5858
expect(response.phoneResponseInfo.sessionInfo).to.eq('session-info');
59-
expect(mock.calls[0].request).to.eql({
60-
tenantId: null,
61-
...request
62-
});
59+
expect(mock.calls[0].request).to.eql(request);
6360
expect(mock.calls[0].method).to.eq('POST');
6461
expect(mock.calls[0].headers!.get(HttpHeader.CONTENT_TYPE)).to.eq(
6562
'application/json'
@@ -90,10 +87,7 @@ describe('api/authentication/startSignInPhoneMfa', () => {
9087
FirebaseError,
9188
'Firebase: The supplied auth credential is malformed or has expired. (auth/invalid-credential).'
9289
);
93-
expect(mock.calls[0].request).to.eql({
94-
tenantId: null,
95-
...request
96-
});
90+
expect(mock.calls[0].request).to.eql(request);
9791
});
9892
});
9993

@@ -126,10 +120,7 @@ describe('api/authentication/finalizeSignInPhoneMfa', () => {
126120
const response = await finalizeSignInPhoneMfa(auth, request);
127121
expect(response.idToken).to.eq('id-token');
128122
expect(response.refreshToken).to.eq('refresh-token');
129-
expect(mock.calls[0].request).to.eql({
130-
tenantId: null,
131-
...request
132-
});
123+
expect(mock.calls[0].request).to.eql(request);
133124
expect(mock.calls[0].method).to.eq('POST');
134125
expect(mock.calls[0].headers!.get(HttpHeader.CONTENT_TYPE)).to.eq(
135126
'application/json'
@@ -160,9 +151,6 @@ describe('api/authentication/finalizeSignInPhoneMfa', () => {
160151
FirebaseError,
161152
'Firebase: The SMS verification code used to create the phone auth credential is invalid. Please resend the verification code sms and be sure to use the verification code provided by the user. (auth/invalid-verification-code).'
162153
);
163-
expect(mock.calls[0].request).to.eql({
164-
tenantId: null,
165-
...request
166-
});
154+
expect(mock.calls[0].request).to.eql(request);
167155
});
168156
});

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

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18-
import { _performApiRequest, Endpoint, HttpMethod } from '../index';
18+
import { _performApiRequest, Endpoint, HttpMethod, _addTidIfNecessary } from '../index';
1919
import { Auth } from '../../model/public_types';
2020
import { IdTokenResponse } from '../../model/id_token';
2121
import { MfaEnrollment } from '../account_management/mfa';
@@ -44,7 +44,7 @@ export interface StartPhoneMfaSignInRequest {
4444
phoneSignInInfo: {
4545
recaptchaToken: string;
4646
};
47-
tenantId: string | null;
47+
tenantId?: string;
4848
}
4949

5050
export interface StartPhoneMfaSignInResponse {
@@ -55,36 +55,30 @@ export interface StartPhoneMfaSignInResponse {
5555

5656
export function startSignInPhoneMfa(
5757
auth: Auth,
58-
request: Omit<StartPhoneMfaSignInRequest, 'tenantId'>
58+
request: StartPhoneMfaSignInRequest
5959
): Promise<StartPhoneMfaSignInResponse> {
6060
return _performApiRequest<
6161
StartPhoneMfaSignInRequest,
6262
StartPhoneMfaSignInResponse
63-
>(auth, HttpMethod.POST, Endpoint.START_PHONE_MFA_SIGN_IN, {
64-
tenantId: auth.tenantId,
65-
...request
66-
});
63+
>(auth, HttpMethod.POST, Endpoint.START_PHONE_MFA_SIGN_IN, _addTidIfNecessary(auth, request));
6764
}
6865

6966
export interface FinalizePhoneMfaSignInRequest {
7067
mfaPendingCredential: string;
7168
phoneVerificationInfo: SignInWithPhoneNumberRequest;
72-
tenantId: string | null;
69+
tenantId?: string;
7370
}
7471

7572
export interface FinalizePhoneMfaSignInResponse extends FinalizeMfaResponse {}
7673

7774
export function finalizeSignInPhoneMfa(
7875
auth: Auth,
79-
request: Omit<FinalizePhoneMfaSignInRequest, 'tenantId'>
76+
request: FinalizePhoneMfaSignInRequest,
8077
): Promise<FinalizePhoneMfaSignInResponse> {
8178
return _performApiRequest<
8279
FinalizePhoneMfaSignInRequest,
8380
FinalizePhoneMfaSignInResponse
84-
>(auth, HttpMethod.POST, Endpoint.FINALIZE_PHONE_MFA_SIGN_IN, {
85-
tenantId: auth.tenantId,
86-
...request
87-
});
81+
>(auth, HttpMethod.POST, Endpoint.FINALIZE_PHONE_MFA_SIGN_IN, _addTidIfNecessary(auth, request));
8882
}
8983

9084
/**

packages/auth/src/mfa/mfa_user.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,6 @@ describe('core/mfa/mfa_user/MultiFactorUser', () => {
189189
expect(withdrawMfaEnrollmentMock.calls[0].request).to.eql({
190190
idToken: 'access-token',
191191
mfaEnrollmentId: mfaInfo.uid,
192-
tenantId: auth.tenantId
193192
});
194193
});
195194

@@ -205,7 +204,6 @@ describe('core/mfa/mfa_user/MultiFactorUser', () => {
205204
expect(withdrawMfaEnrollmentMock.calls[0].request).to.eql({
206205
idToken: 'access-token',
207206
mfaEnrollmentId: mfaInfo.uid,
208-
tenantId: auth.tenantId
209207
});
210208
});
211209

packages/auth/src/platform_browser/mfa/assertions/phone.test.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ describe('platform_browser/mfa/phone', () => {
7070
expect(response).to.eql(serverResponse);
7171
expect(mock.calls[0].request).to.eql({
7272
idToken: 'enrollment-id-token',
73-
tenantId: auth.tenantId,
7473
phoneVerificationInfo: {
7574
code: 'verification-code',
7675
sessionInfo: 'verification-id'
@@ -93,7 +92,6 @@ describe('platform_browser/mfa/phone', () => {
9392
expect(mock.calls[0].request).to.eql({
9493
idToken: 'enrollment-id-token',
9594
displayName: 'display-name',
96-
tenantId: auth.tenantId,
9795
phoneVerificationInfo: {
9896
code: 'verification-code',
9997
sessionInfo: 'verification-id'
@@ -119,7 +117,6 @@ describe('platform_browser/mfa/phone', () => {
119117
expect(response).to.eql(serverResponse);
120118
expect(mock.calls[0].request).to.eql({
121119
mfaPendingCredential: 'mfa-pending-credential',
122-
tenantId: null,
123120
phoneVerificationInfo: {
124121
code: 'verification-code',
125122
sessionInfo: 'verification-id'

packages/auth/src/platform_browser/strategies/phone.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,6 @@ describe('platform_browser/strategies/phone', () => {
336336
);
337337
expect(sessionInfo).to.eq('session-info');
338338
expect(endpoint.calls[0].request).to.eql({
339-
tenantId: auth.tenantId,
340339
idToken: session.credential,
341340
phoneEnrollmentInfo: {
342341
phoneNumber: 'number',
@@ -369,7 +368,6 @@ describe('platform_browser/strategies/phone', () => {
369368
);
370369
expect(sessionInfo).to.eq('session-info');
371370
expect(endpoint.calls[0].request).to.eql({
372-
tenantId: auth.tenantId,
373371
mfaPendingCredential: 'mfa-pending-credential',
374372
mfaEnrollmentId: 'mfa-enrollment-id',
375373
phoneSignInInfo: {

0 commit comments

Comments
 (0)