Skip to content

Commit fe8387e

Browse files
authored
GCIP BYO-CIAM Initialize Auth Changes (#8995)
* Implement InitializeAuth changes for BYO-CIAM Firebase Auth * Removing white space * Addressing review comments * Adding Unit test for initializeAuth with TenantConfig dependency * Running yarn run demo * Update doc
1 parent 080a90d commit fe8387e

File tree

9 files changed

+126
-4
lines changed

9 files changed

+126
-4
lines changed

common/api-review/auth.api.md

+7
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ export interface Dependencies {
316316
errorMap?: AuthErrorMap;
317317
persistence?: Persistence | Persistence[];
318318
popupRedirectResolver?: PopupRedirectResolver;
319+
tenantConfig?: TenantConfig;
319320
}
320321

321322
// @public
@@ -795,6 +796,12 @@ export function signInWithRedirect(auth: Auth, provider: AuthProvider, resolver?
795796
// @public
796797
export function signOut(auth: Auth): Promise<void>;
797798

799+
// @public
800+
export interface TenantConfig {
801+
location: string;
802+
tenantId: string;
803+
}
804+
798805
// @public
799806
export interface TotpMultiFactorAssertion extends MultiFactorAssertion {
800807
}

docs-devsite/_toc.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ toc:
155155
path: /docs/reference/js/auth.recaptchaverifier.md
156156
- title: SAMLAuthProvider
157157
path: /docs/reference/js/auth.samlauthprovider.md
158+
- title: TenantConfig
159+
path: /docs/reference/js/auth.tenantconfig.md
158160
- title: TotpMultiFactorAssertion
159161
path: /docs/reference/js/auth.totpmultifactorassertion.md
160162
- title: TotpMultiFactorGenerator

docs-devsite/auth.dependencies.md

+11
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export interface Dependencies
2929
| [errorMap](./auth.dependencies.md#dependencieserrormap) | [AuthErrorMap](./auth.autherrormap.md#autherrormap_interface) | Which [AuthErrorMap](./auth.autherrormap.md#autherrormap_interface) to use. |
3030
| [persistence](./auth.dependencies.md#dependenciespersistence) | [Persistence](./auth.persistence.md#persistence_interface) \| [Persistence](./auth.persistence.md#persistence_interface)<!-- -->\[\] | Which [Persistence](./auth.persistence.md#persistence_interface) to use. If this is an array, the first <code>Persistence</code> that the device supports is used. The SDK searches for an existing account in order and, if one is found in a secondary <code>Persistence</code>, the account is moved to the primary <code>Persistence</code>.<!-- -->If no persistence is provided, the SDK falls back on [inMemoryPersistence](./auth.md#inmemorypersistence)<!-- -->. |
3131
| [popupRedirectResolver](./auth.dependencies.md#dependenciespopupredirectresolver) | [PopupRedirectResolver](./auth.popupredirectresolver.md#popupredirectresolver_interface) | The [PopupRedirectResolver](./auth.popupredirectresolver.md#popupredirectresolver_interface) to use. This value depends on the platform. Options are [browserPopupRedirectResolver](./auth.md#browserpopupredirectresolver) and [cordovaPopupRedirectResolver](./auth.md#cordovapopupredirectresolver)<!-- -->. This field is optional if neither [signInWithPopup()](./auth.md#signinwithpopup_770f816) or [signInWithRedirect()](./auth.md#signinwithredirect_770f816) are being used. |
32+
| [tenantConfig](./auth.dependencies.md#dependenciestenantconfig) | [TenantConfig](./auth.tenantconfig.md#tenantconfig_interface) | The [TenantConfig](./auth.tenantconfig.md#tenantconfig_interface) to use. This dependency is only required if you want to use regional auth which works with endpoint. It should not be set otherwise. |
3233

3334
## Dependencies.errorMap
3435

@@ -61,3 +62,13 @@ The [PopupRedirectResolver](./auth.popupredirectresolver.md#popupredirectresolve
6162
```typescript
6263
popupRedirectResolver?: PopupRedirectResolver;
6364
```
65+
66+
## Dependencies.tenantConfig
67+
68+
The [TenantConfig](./auth.tenantconfig.md#tenantconfig_interface) to use. This dependency is only required if you want to use regional auth which works with endpoint. It should not be set otherwise.
69+
70+
<b>Signature:</b>
71+
72+
```typescript
73+
tenantConfig?: TenantConfig;
74+
```

docs-devsite/auth.md

+1
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ Firebase Authentication
137137
| [PopupRedirectResolver](./auth.popupredirectresolver.md#popupredirectresolver_interface) | A resolver used for handling DOM specific operations like [signInWithPopup()](./auth.md#signinwithpopup_770f816) or [signInWithRedirect()](./auth.md#signinwithredirect_770f816)<!-- -->. |
138138
| [ReactNativeAsyncStorage](./auth.reactnativeasyncstorage.md#reactnativeasyncstorage_interface) | Interface for a supplied <code>AsyncStorage</code>. |
139139
| [RecaptchaParameters](./auth.recaptchaparameters.md#recaptchaparameters_interface) | Interface representing reCAPTCHA parameters.<!-- -->See the [reCAPTCHA docs](https://developers.google.com/recaptcha/docs/display#render_param) for the list of accepted parameters. All parameters are accepted except for <code>sitekey</code>: Firebase Auth provisions a reCAPTCHA for each project and will configure the site key upon rendering.<!-- -->For an invisible reCAPTCHA, set the <code>size</code> key to <code>invisible</code>. |
140+
| [TenantConfig](./auth.tenantconfig.md#tenantconfig_interface) | The tenant config that can be used to initialize a Regional [Auth](./auth.auth.md#auth_interface) instance. |
140141
| [TotpMultiFactorAssertion](./auth.totpmultifactorassertion.md#totpmultifactorassertion_interface) | The class for asserting ownership of a TOTP second factor. Provided by [TotpMultiFactorGenerator.assertionForEnrollment()](./auth.totpmultifactorgenerator.md#totpmultifactorgeneratorassertionforenrollment) and [TotpMultiFactorGenerator.assertionForSignIn()](./auth.totpmultifactorgenerator.md#totpmultifactorgeneratorassertionforsignin)<!-- -->. |
141142
| [TotpMultiFactorInfo](./auth.totpmultifactorinfo.md#totpmultifactorinfo_interface) | The subclass of the [MultiFactorInfo](./auth.multifactorinfo.md#multifactorinfo_interface) interface for TOTP second factors. The <code>factorId</code> of this second factor is [FactorId](./auth.md#factorid)<!-- -->.TOTP. |
142143
| [User](./auth.user.md#user_interface) | A user account. |

docs-devsite/auth.tenantconfig.md

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
Project: /docs/reference/js/_project.yaml
2+
Book: /docs/reference/_book.yaml
3+
page_type: reference
4+
5+
{% comment %}
6+
DO NOT EDIT THIS FILE!
7+
This is generated by the JS SDK team, and any local changes will be
8+
overwritten. Changes should be made in the source code at
9+
https://github.com/firebase/firebase-js-sdk
10+
{% endcomment %}
11+
12+
# TenantConfig interface
13+
The tenant config that can be used to initialize a Regional [Auth](./auth.auth.md#auth_interface) instance.
14+
15+
<b>Signature:</b>
16+
17+
```typescript
18+
export interface TenantConfig
19+
```
20+
21+
## Properties
22+
23+
| Property | Type | Description |
24+
| --- | --- | --- |
25+
| [location](./auth.tenantconfig.md#tenantconfiglocation) | string | Which location to use. |
26+
| [tenantId](./auth.tenantconfig.md#tenantconfigtenantid) | string | The tenant Id being used. |
27+
28+
## TenantConfig.location
29+
30+
Which location to use.
31+
32+
<b>Signature:</b>
33+
34+
```typescript
35+
location: string;
36+
```
37+
38+
## TenantConfig.tenantId
39+
40+
The tenant Id being used.
41+
42+
<b>Signature:</b>
43+
44+
```typescript
45+
tenantId: string;
46+
```

packages/auth/src/core/auth/auth_impl.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ interface AsyncAction {
9191
export const enum DefaultConfig {
9292
TOKEN_API_HOST = 'securetoken.googleapis.com',
9393
API_HOST = 'identitytoolkit.googleapis.com',
94-
API_SCHEME = 'https'
94+
API_SCHEME = 'https',
95+
REGIONAL_API_HOST = 'identityplatform.googleapis.com'
9596
}
9697

9798
export class AuthImpl implements AuthInternal, _FirebaseService {

packages/auth/src/core/auth/initialize.test.ts

+31-2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
AuthProvider,
2727
Persistence as PersistencePublic,
2828
PopupRedirectResolver,
29+
TenantConfig,
2930
UserCredential
3031
} from '../../model/public_types';
3132
import { isNode } from '@firebase/util';
@@ -51,6 +52,7 @@ import { ClientPlatform, _getClientVersion } from '../util/version';
5152
import { initializeAuth } from './initialize';
5253
import { registerAuth } from './register';
5354
import { debugErrorMap, prodErrorMap } from '../errors';
55+
import { DefaultConfig } from './auth_impl';
5456

5557
describe('core/auth/initialize', () => {
5658
let fakeApp: FirebaseApp;
@@ -132,6 +134,11 @@ describe('core/auth/initialize', () => {
132134
const fakePopupRedirectResolver: PopupRedirectResolver =
133135
FakePopupRedirectResolver;
134136

137+
const fakeTenantConfig: TenantConfig = {
138+
'location': 'us',
139+
'tenantId': 'tenant-1'
140+
};
141+
135142
before(() => {
136143
registerAuth(ClientPlatform.BROWSER);
137144
});
@@ -202,6 +209,15 @@ describe('core/auth/initialize', () => {
202209
);
203210
});
204211

212+
it('should set TenantConfig', async () => {
213+
const auth = initializeAuth(fakeApp, {
214+
tenantConfig: fakeTenantConfig
215+
}) as AuthInternal;
216+
await auth._initializationPromise;
217+
218+
expect(auth.config.apiHost).equal(DefaultConfig.REGIONAL_API_HOST);
219+
});
220+
205221
it('should abort initialization if deleted synchronously', async () => {
206222
const auth = initializeAuth(fakeApp, {
207223
popupRedirectResolver: fakePopupRedirectResolver
@@ -221,13 +237,15 @@ describe('core/auth/initialize', () => {
221237
const auth = initializeAuth(fakeApp, {
222238
errorMap: prodErrorMap,
223239
persistence: fakeSessionPersistence,
224-
popupRedirectResolver: fakePopupRedirectResolver
240+
popupRedirectResolver: fakePopupRedirectResolver,
241+
tenantConfig: fakeTenantConfig
225242
});
226243
expect(
227244
initializeAuth(fakeApp, {
228245
errorMap: prodErrorMap,
229246
persistence: fakeSessionPersistence,
230-
popupRedirectResolver: fakePopupRedirectResolver
247+
popupRedirectResolver: fakePopupRedirectResolver,
248+
tenantConfig: fakeTenantConfig
231249
})
232250
).to.equal(auth);
233251
});
@@ -264,5 +282,16 @@ describe('core/auth/initialize', () => {
264282
})
265283
).to.throw();
266284
});
285+
286+
it('should throw if called again with different params (TenantConfig)', () => {
287+
initializeAuth(fakeApp, {
288+
tenantConfig: fakeTenantConfig
289+
});
290+
expect(() =>
291+
initializeAuth(fakeApp, {
292+
tenantConfig: undefined
293+
})
294+
).to.throw();
295+
});
267296
});
268297
});

packages/auth/src/core/auth/register.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export function registerAuth(clientPlatform: ClientPlatform): void {
6868
const appCheckServiceProvider =
6969
container.getProvider<'app-check-internal'>('app-check-internal');
7070
const { apiKey, authDomain } = app.options;
71+
const tenantConfig = deps?.tenantConfig;
7172

7273
_assert(
7374
apiKey && !apiKey.includes(':'),
@@ -79,7 +80,9 @@ export function registerAuth(clientPlatform: ClientPlatform): void {
7980
apiKey,
8081
authDomain,
8182
clientPlatform,
82-
apiHost: DefaultConfig.API_HOST,
83+
apiHost: tenantConfig?.location
84+
? DefaultConfig.REGIONAL_API_HOST
85+
: DefaultConfig.API_HOST,
8386
tokenApiHost: DefaultConfig.TOKEN_API_HOST,
8487
apiScheme: DefaultConfig.API_SCHEME,
8588
sdkClientVersion: _getClientVersion(clientPlatform)

packages/auth/src/model/public_types.ts

+22
Original file line numberDiff line numberDiff line change
@@ -1260,6 +1260,28 @@ export interface Dependencies {
12601260
* Which {@link AuthErrorMap} to use.
12611261
*/
12621262
errorMap?: AuthErrorMap;
1263+
/**
1264+
* The {@link TenantConfig} to use. This dependency is only required
1265+
* if you want to use regional auth which works with
1266+
* {@link DefaultConfig.REGIONAL_API_HOST} endpoint. It should not be set otherwise.
1267+
*/
1268+
tenantConfig?: TenantConfig;
1269+
}
1270+
1271+
/**
1272+
* The tenant config that can be used to initialize a Regional {@link Auth} instance.
1273+
*
1274+
* @public
1275+
*/
1276+
export interface TenantConfig {
1277+
/**
1278+
* Which location to use.
1279+
*/
1280+
location: string;
1281+
/**
1282+
* The tenant Id being used.
1283+
*/
1284+
tenantId: string;
12631285
}
12641286

12651287
/**

0 commit comments

Comments
 (0)