Skip to content

Commit 8dab8e1

Browse files
authored
[Auth] Add multi-tenant support where missing to API surface (#4615)
* Multi tenant support * Formatting
1 parent 6b336dc commit 8dab8e1

18 files changed

+201
-38
lines changed

packages-exp/auth-exp/src/api/account_management/email_and_password.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,10 @@ describe('api/account_management/resetPassword', () => {
5353
5454
});
5555

56+
auth.tenantId = 'tenant-id';
5657
const response = await resetPassword(auth, request);
5758
expect(response.email).to.eq('[email protected]');
58-
expect(mock.calls[0].request).to.eql(request);
59+
expect(mock.calls[0].request).to.eql({ ...request, tenantId: 'tenant-id' });
5960
expect(mock.calls[0].method).to.eq('POST');
6061
expect(mock.calls[0].headers!.get(HttpHeader.CONTENT_TYPE)).to.eq(
6162
'application/json'
@@ -166,9 +167,10 @@ describe('api/account_management/applyActionCode', () => {
166167
it('should POST to the correct endpoint', async () => {
167168
const mock = mockEndpoint(Endpoint.SET_ACCOUNT_INFO, {});
168169

170+
auth.tenantId = 'tenant-id';
169171
const response = await applyActionCode(auth, request);
170172
expect(response).to.be.empty;
171-
expect(mock.calls[0].request).to.eql(request);
173+
expect(mock.calls[0].request).to.eql({ ...request, tenantId: 'tenant-id' });
172174
expect(mock.calls[0].method).to.eq('POST');
173175
expect(mock.calls[0].headers!.get(HttpHeader.CONTENT_TYPE)).to.eq(
174176
'application/json'

packages-exp/auth-exp/src/api/account_management/email_and_password.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,19 @@
1717

1818
import { ActionCodeOperation, Auth } from '../../model/public_types';
1919

20-
import { Endpoint, HttpMethod, _performApiRequest } from '../index';
20+
import {
21+
Endpoint,
22+
HttpMethod,
23+
_addTidIfNecessary,
24+
_performApiRequest
25+
} from '../index';
2126
import { IdTokenResponse } from '../../model/id_token';
2227
import { MfaEnrollment } from './mfa';
2328

2429
export interface ResetPasswordRequest {
2530
oobCode: string;
2631
newPassword?: string;
32+
tenantId?: string;
2733
}
2834

2935
export interface ResetPasswordResponse {
@@ -41,7 +47,7 @@ export async function resetPassword(
4147
auth,
4248
HttpMethod.POST,
4349
Endpoint.RESET_PASSWORD,
44-
request
50+
_addTidIfNecessary(auth, request)
4551
);
4652
}
4753
export interface UpdateEmailPasswordRequest {
@@ -65,6 +71,7 @@ export async function updateEmailPassword(
6571

6672
export interface ApplyActionCodeRequest {
6773
oobCode: string;
74+
tenantId?: string;
6875
}
6976

7077
export interface ApplyActionCodeResponse {}
@@ -77,6 +84,6 @@ export async function applyActionCode(
7784
auth,
7885
HttpMethod.POST,
7986
Endpoint.SET_ACCOUNT_INFO,
80-
request
87+
_addTidIfNecessary(auth, request)
8188
);
8289
}

packages-exp/auth-exp/src/api/authentication/create_auth_uri.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,10 @@ describe('api/authentication/createAuthUri', () => {
4949
signinMethods: ['email']
5050
});
5151

52+
auth.tenantId = 'tenant-id';
5253
const response = await createAuthUri(auth, request);
5354
expect(response.signinMethods).to.include('email');
54-
expect(mock.calls[0].request).to.eql(request);
55+
expect(mock.calls[0].request).to.eql({ ...request, tenantId: 'tenant-id' });
5556
expect(mock.calls[0].method).to.eq('POST');
5657
expect(mock.calls[0].headers!.get(HttpHeader.CONTENT_TYPE)).to.eq(
5758
'application/json'

packages-exp/auth-exp/src/api/authentication/create_auth_uri.ts

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

18-
import { Endpoint, HttpMethod, _performApiRequest } from '../index';
18+
import {
19+
Endpoint,
20+
HttpMethod,
21+
_addTidIfNecessary,
22+
_performApiRequest
23+
} from '../index';
1924
import { Auth } from '../../model/public_types';
2025

2126
export interface CreateAuthUriRequest {
2227
identifier: string;
2328
continueUri: string;
29+
tenantId?: string;
2430
}
2531

2632
export interface CreateAuthUriResponse {
@@ -35,6 +41,6 @@ export async function createAuthUri(
3541
auth,
3642
HttpMethod.POST,
3743
Endpoint.CREATE_AUTH_URI,
38-
request
44+
_addTidIfNecessary(auth, request)
3945
);
4046
}

packages-exp/auth-exp/src/api/authentication/custom_token.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,13 @@ describe('api/authentication/signInWithCustomToken', () => {
5353
localId: '1234'
5454
});
5555

56+
auth.tenantId = 'tenant-id';
5657
const response = await signInWithCustomToken(auth, request);
5758
expect(response.providerId).to.eq(ProviderId.CUSTOM);
5859
expect(response.idToken).to.eq('id-token');
5960
expect(response.expiresIn).to.eq('1000');
6061
expect(response.localId).to.eq('1234');
61-
expect(mock.calls[0].request).to.eql(request);
62+
expect(mock.calls[0].request).to.eql({ ...request, tenantId: 'tenant-id' });
6263
expect(mock.calls[0].method).to.eq('POST');
6364
expect(mock.calls[0].headers!.get(HttpHeader.CONTENT_TYPE)).to.eq(
6465
'application/json'

packages-exp/auth-exp/src/api/authentication/custom_token.ts

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

18-
import { Endpoint, HttpMethod, _performSignInRequest } from '../index';
18+
import {
19+
Endpoint,
20+
HttpMethod,
21+
_addTidIfNecessary,
22+
_performSignInRequest
23+
} from '../index';
1924
import { IdTokenResponse } from '../../model/id_token';
2025
import { Auth } from '../../model/public_types';
2126

2227
export interface SignInWithCustomTokenRequest {
2328
token: string;
2429
returnSecureToken: boolean;
30+
tenantId?: string;
2531
}
2632

2733
export interface SignInWithCustomTokenResponse extends IdTokenResponse {}
@@ -33,5 +39,10 @@ export async function signInWithCustomToken(
3339
return _performSignInRequest<
3440
SignInWithCustomTokenRequest,
3541
SignInWithCustomTokenResponse
36-
>(auth, HttpMethod.POST, Endpoint.SIGN_IN_WITH_CUSTOM_TOKEN, request);
42+
>(
43+
auth,
44+
HttpMethod.POST,
45+
Endpoint.SIGN_IN_WITH_CUSTOM_TOKEN,
46+
_addTidIfNecessary(auth, request)
47+
);
3748
}

packages-exp/auth-exp/src/api/authentication/email_and_password.test.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,11 @@ describe('api/authentication/signInWithPassword', () => {
6262
6363
});
6464

65+
auth.tenantId = 'tenant-id';
6566
const response = await signInWithPassword(auth, request);
6667
expect(response.displayName).to.eq('my-name');
6768
expect(response.email).to.eq('[email protected]');
68-
expect(mock.calls[0].request).to.eql(request);
69+
expect(mock.calls[0].request).to.eql({ ...request, tenantId: 'tenant-id' });
6970
expect(mock.calls[0].method).to.eq('POST');
7071
expect(mock.calls[0].headers!.get(HttpHeader.CONTENT_TYPE)).to.eq(
7172
'application/json'
@@ -120,9 +121,10 @@ describe('api/authentication/sendEmailVerification', () => {
120121
121122
});
122123

124+
auth.tenantId = 'tenant-id';
123125
const response = await sendEmailVerification(auth, request);
124126
expect(response.email).to.eq('[email protected]');
125-
expect(mock.calls[0].request).to.eql(request);
127+
expect(mock.calls[0].request).to.eql({ ...request, tenantId: 'tenant-id' });
126128
expect(mock.calls[0].method).to.eq('POST');
127129
expect(mock.calls[0].headers!.get(HttpHeader.CONTENT_TYPE)).to.eq(
128130
'application/json'
@@ -177,9 +179,10 @@ describe('api/authentication/sendPasswordResetEmail', () => {
177179
178180
});
179181

182+
auth.tenantId = 'tenant-id';
180183
const response = await sendPasswordResetEmail(auth, request);
181184
expect(response.email).to.eq('[email protected]');
182-
expect(mock.calls[0].request).to.eql(request);
185+
expect(mock.calls[0].request).to.eql({ ...request, tenantId: 'tenant-id' });
183186
expect(mock.calls[0].method).to.eq('POST');
184187
expect(mock.calls[0].headers!.get(HttpHeader.CONTENT_TYPE)).to.eq(
185188
'application/json'
@@ -234,9 +237,10 @@ describe('api/authentication/sendSignInLinkToEmail', () => {
234237
235238
});
236239

240+
auth.tenantId = 'tenant-id';
237241
const response = await sendSignInLinkToEmail(auth, request);
238242
expect(response.email).to.eq('[email protected]');
239-
expect(mock.calls[0].request).to.eql(request);
243+
expect(mock.calls[0].request).to.eql({ ...request, tenantId: 'tenant-id' });
240244
expect(mock.calls[0].method).to.eq('POST');
241245
expect(mock.calls[0].headers!.get(HttpHeader.CONTENT_TYPE)).to.eq(
242246
'application/json'
@@ -292,9 +296,10 @@ describe('api/authentication/verifyAndChangeEmail', () => {
292296
293297
});
294298

299+
auth.tenantId = 'tenant-id';
295300
const response = await verifyAndChangeEmail(auth, request);
296301
expect(response.email).to.eq('[email protected]');
297-
expect(mock.calls[0].request).to.eql(request);
302+
expect(mock.calls[0].request).to.eql({ ...request, tenantId: 'tenant-id' });
298303
expect(mock.calls[0].method).to.eq('POST');
299304
expect(mock.calls[0].headers!.get(HttpHeader.CONTENT_TYPE)).to.eq(
300305
'application/json'

packages-exp/auth-exp/src/api/authentication/email_and_password.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { ActionCodeOperation, Auth } from '../../model/public_types';
2020
import {
2121
Endpoint,
2222
HttpMethod,
23+
_addTidIfNecessary,
2324
_performApiRequest,
2425
_performSignInRequest
2526
} from '../index';
@@ -29,6 +30,7 @@ export interface SignInWithPasswordRequest {
2930
returnSecureToken?: boolean;
3031
email: string;
3132
password: string;
33+
tenantId?: string;
3234
}
3335

3436
export interface SignInWithPasswordResponse extends IdTokenResponse {
@@ -43,7 +45,12 @@ export async function signInWithPassword(
4345
return _performSignInRequest<
4446
SignInWithPasswordRequest,
4547
SignInWithPasswordResponse
46-
>(auth, HttpMethod.POST, Endpoint.SIGN_IN_WITH_PASSWORD, request);
48+
>(
49+
auth,
50+
HttpMethod.POST,
51+
Endpoint.SIGN_IN_WITH_PASSWORD,
52+
_addTidIfNecessary(auth, request)
53+
);
4754
}
4855

4956
export interface GetOobCodeRequest {
@@ -99,7 +106,7 @@ async function sendOobCode(
99106
auth,
100107
HttpMethod.POST,
101108
Endpoint.SEND_OOB_CODE,
102-
request
109+
_addTidIfNecessary(auth, request)
103110
);
104111
}
105112

packages-exp/auth-exp/src/api/authentication/email_link.test.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,14 @@ describe('api/authentication/email_link', () => {
5454
5555
});
5656

57+
auth.tenantId = 'tenant-id';
5758
const response = await signInWithEmailLink(auth, request);
5859
expect(response.displayName).to.eq('my-name');
5960
expect(response.email).to.eq('[email protected]');
60-
expect(mock.calls[0].request).to.eql(request);
61+
expect(mock.calls[0].request).to.eql({
62+
...request,
63+
tenantId: 'tenant-id'
64+
});
6165
expect(mock.calls[0].method).to.eq('POST');
6266
expect(mock.calls[0].headers!.get(HttpHeader.CONTENT_TYPE)).to.eq(
6367
'application/json'
@@ -105,10 +109,14 @@ describe('api/authentication/email_link', () => {
105109
106110
});
107111

112+
auth.tenantId = 'tenant-id';
108113
const response = await signInWithEmailLinkForLinking(auth, request);
109114
expect(response.displayName).to.eq('my-name');
110115
expect(response.email).to.eq('[email protected]');
111-
expect(mock.calls[0].request).to.eql(request);
116+
expect(mock.calls[0].request).to.eql({
117+
...request,
118+
tenantId: 'tenant-id'
119+
});
112120
expect(mock.calls[0].method).to.eq('POST');
113121
expect(mock.calls[0].headers!.get(HttpHeader.CONTENT_TYPE)).to.eq(
114122
'application/json'

packages-exp/auth-exp/src/api/authentication/email_link.ts

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

18-
import { _performSignInRequest, Endpoint, HttpMethod } from '../index';
18+
import {
19+
_performSignInRequest,
20+
Endpoint,
21+
HttpMethod,
22+
_addTidIfNecessary
23+
} from '../index';
1924
import { IdTokenResponse } from '../../model/id_token';
2025
import { Auth } from '../../model/public_types';
2126

2227
export interface SignInWithEmailLinkRequest {
2328
email: string;
2429
oobCode: string;
30+
tenantId?: string;
2531
}
2632

2733
export interface SignInWithEmailLinkResponse extends IdTokenResponse {
@@ -36,7 +42,12 @@ export async function signInWithEmailLink(
3642
return _performSignInRequest<
3743
SignInWithEmailLinkRequest,
3844
SignInWithEmailLinkResponse
39-
>(auth, HttpMethod.POST, Endpoint.SIGN_IN_WITH_EMAIL_LINK, request);
45+
>(
46+
auth,
47+
HttpMethod.POST,
48+
Endpoint.SIGN_IN_WITH_EMAIL_LINK,
49+
_addTidIfNecessary(auth, request)
50+
);
4051
}
4152

4253
export interface SignInWithEmailLinkForLinkingRequest
@@ -51,5 +62,10 @@ export async function signInWithEmailLinkForLinking(
5162
return _performSignInRequest<
5263
SignInWithEmailLinkForLinkingRequest,
5364
SignInWithEmailLinkResponse
54-
>(auth, HttpMethod.POST, Endpoint.SIGN_IN_WITH_EMAIL_LINK, request);
65+
>(
66+
auth,
67+
HttpMethod.POST,
68+
Endpoint.SIGN_IN_WITH_EMAIL_LINK,
69+
_addTidIfNecessary(auth, request)
70+
);
5571
}

packages-exp/auth-exp/src/api/authentication/idp.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,11 @@ describe('api/authentication/signInWithIdp', () => {
5050
idToken: 'id-token'
5151
});
5252

53+
auth.tenantId = 'tenant-id';
5354
const response = await signInWithIdp(auth, request);
5455
expect(response.displayName).to.eq('my-name');
5556
expect(response.idToken).to.eq('id-token');
56-
expect(mock.calls[0].request).to.eql(request);
57+
expect(mock.calls[0].request).to.eql({ ...request, tenantId: 'tenant-id' });
5758
expect(mock.calls[0].method).to.eq('POST');
5859
expect(mock.calls[0].headers!.get(HttpHeader.CONTENT_TYPE)).to.eq(
5960
'application/json'

packages-exp/auth-exp/src/api/authentication/idp.ts

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

18-
import { Endpoint, HttpMethod, _performSignInRequest } from '../index';
18+
import {
19+
Endpoint,
20+
HttpMethod,
21+
_addTidIfNecessary,
22+
_performSignInRequest
23+
} from '../index';
1924
import { IdToken, IdTokenResponse } from '../../model/id_token';
2025
import { Auth } from '../../model/public_types';
2126

@@ -47,6 +52,6 @@ export async function signInWithIdp(
4752
auth,
4853
HttpMethod.POST,
4954
Endpoint.SIGN_IN_WITH_IDP,
50-
request
55+
_addTidIfNecessary(auth, request)
5156
);
5257
}

packages-exp/auth-exp/src/api/authentication/sign_up.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,11 @@ describe('api/authentication/signUp', () => {
5151
5252
});
5353

54+
auth.tenantId = 'tenant-id';
5455
const response = await signUp(auth, request);
5556
expect(response.displayName).to.eq('my-name');
5657
expect(response.email).to.eq('[email protected]');
57-
expect(mock.calls[0].request).to.eql(request);
58+
expect(mock.calls[0].request).to.eql({ ...request, tenantId: 'tenant-id' });
5859
expect(mock.calls[0].method).to.eq('POST');
5960
expect(mock.calls[0].headers!.get(HttpHeader.CONTENT_TYPE)).to.eq(
6061
'application/json'

0 commit comments

Comments
 (0)