Skip to content

Commit 1a92508

Browse files
authored
Merge 776dc7a into ac2fc52
2 parents ac2fc52 + 776dc7a commit 1a92508

18 files changed

+510
-5611
lines changed

common/api-review/auth.api.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,13 @@ export interface Auth {
8888
readonly config: Config;
8989
readonly currentUser: User | null;
9090
readonly emulatorConfig: EmulatorConfig | null;
91-
readonly firebaseToken: FirebaseToken | null;
9291
languageCode: string | null;
9392
readonly name: string;
9493
onAuthStateChanged(nextOrObserver: NextOrObserver<User | null>, error?: ErrorFn, completed?: CompleteFn): Unsubscribe;
9594
onIdTokenChanged(nextOrObserver: NextOrObserver<User | null>, error?: ErrorFn, completed?: CompleteFn): Unsubscribe;
9695
setPersistence(persistence: Persistence): Promise<void>;
9796
readonly settings: AuthSettings;
97+
setTokenRefreshHandler(tokenRefreshHandler: TokenRefreshHandler): void;
9898
signOut(): Promise<void>;
9999
readonly tenantConfig?: TenantConfig;
100100
tenantId: string | null;
@@ -389,14 +389,6 @@ export const FactorId: {
389389
// @public
390390
export function fetchSignInMethodsForEmail(auth: Auth, email: string): Promise<string[]>;
391391

392-
// @public (undocumented)
393-
export interface FirebaseToken {
394-
// (undocumented)
395-
readonly expirationTime: number;
396-
// (undocumented)
397-
readonly token: string;
398-
}
399-
400392
// @public
401393
export function getAdditionalUserInfo(userCredential: UserCredential): AdditionalUserInfo | null;
402394

@@ -743,6 +735,12 @@ export class RecaptchaVerifier implements ApplicationVerifierInternal {
743735
verify(): Promise<string>;
744736
}
745737

738+
// @public
739+
export interface RefreshIdpTokenResult {
740+
idpConfigId: string;
741+
idToken: string;
742+
}
743+
746744
// @public
747745
export function reload(user: User): Promise<void>;
748746

@@ -815,6 +813,11 @@ export interface TenantConfig {
815813
tenantId: string;
816814
}
817815

816+
// @public
817+
export interface TokenRefreshHandler {
818+
refreshIdpToken(): Promise<RefreshIdpTokenResult>;
819+
}
820+
818821
// @public
819822
export interface TotpMultiFactorAssertion extends MultiFactorAssertion {
820823
}

docs-devsite/_toc.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,6 @@ toc:
310310
path: /docs/reference/js/auth.emulatorconfig.md
311311
- title: FacebookAuthProvider
312312
path: /docs/reference/js/auth.facebookauthprovider.md
313-
- title: FirebaseToken
314-
path: /docs/reference/js/auth.firebasetoken.md
315313
- title: GithubAuthProvider
316314
path: /docs/reference/js/auth.githubauthprovider.md
317315
- title: GoogleAuthProvider
@@ -368,10 +366,14 @@ toc:
368366
path: /docs/reference/js/auth.recaptchaparameters.md
369367
- title: RecaptchaVerifier
370368
path: /docs/reference/js/auth.recaptchaverifier.md
369+
- title: RefreshIdpTokenResult
370+
path: /docs/reference/js/auth.refreshidptokenresult.md
371371
- title: SAMLAuthProvider
372372
path: /docs/reference/js/auth.samlauthprovider.md
373373
- title: TenantConfig
374374
path: /docs/reference/js/auth.tenantconfig.md
375+
- title: TokenRefreshHandler
376+
path: /docs/reference/js/auth.tokenrefreshhandler.md
375377
- title: TotpMultiFactorAssertion
376378
path: /docs/reference/js/auth.totpmultifactorassertion.md
377379
- title: TotpMultiFactorGenerator

docs-devsite/auth.auth.md

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ export interface Auth
2828
| [config](./auth.auth.md#authconfig) | [Config](./auth.config.md#config_interface) | The [Config](./auth.config.md#config_interface) used to initialize this instance. |
2929
| [currentUser](./auth.auth.md#authcurrentuser) | [User](./auth.user.md#user_interface) \| null | The currently signed-in user (or null). |
3030
| [emulatorConfig](./auth.auth.md#authemulatorconfig) | [EmulatorConfig](./auth.emulatorconfig.md#emulatorconfig_interface) \| null | The current emulator configuration (or null). |
31-
| [firebaseToken](./auth.auth.md#authfirebasetoken) | [FirebaseToken](./auth.firebasetoken.md#firebasetoken_interface) \| null | The token response initialized via [exchangeToken()](./auth.md#exchangetoken_b6b1871) endpoint. |
3231
| [languageCode](./auth.auth.md#authlanguagecode) | string \| null | The [Auth](./auth.auth.md#auth_interface) instance's language code. |
3332
| [name](./auth.auth.md#authname) | string | The name of the app associated with the <code>Auth</code> service instance. |
3433
| [settings](./auth.auth.md#authsettings) | [AuthSettings](./auth.authsettings.md#authsettings_interface) | The [Auth](./auth.auth.md#auth_interface) instance's settings. |
@@ -44,6 +43,7 @@ export interface Auth
4443
| [onAuthStateChanged(nextOrObserver, error, completed)](./auth.auth.md#authonauthstatechanged) | Adds an observer for changes to the user's sign-in state. |
4544
| [onIdTokenChanged(nextOrObserver, error, completed)](./auth.auth.md#authonidtokenchanged) | Adds an observer for changes to the signed-in user's ID token. |
4645
| [setPersistence(persistence)](./auth.auth.md#authsetpersistence) | Changes the type of persistence on the <code>Auth</code> instance. |
46+
| [setTokenRefreshHandler(tokenRefreshHandler)](./auth.auth.md#authsettokenrefreshhandler) | Registers a handler for refreshing third-party identity provider (IDP) tokens.<!-- -->When the Firebase access token is expired, the SDK will automatically invoke the provided handler's <code>refreshIdpToken()</code> method to obtain a new IDP token. This new token will then be exchanged for a fresh Firebase token, streamlining the authentication process. |
4747
| [signOut()](./auth.auth.md#authsignout) | Signs out the current user. This does not automatically revoke the user's ID token. |
4848
| [updateCurrentUser(user)](./auth.auth.md#authupdatecurrentuser) | Asynchronously sets the provided user as [Auth.currentUser](./auth.auth.md#authcurrentuser) on the [Auth](./auth.auth.md#auth_interface) instance. |
4949
| [useDeviceLanguage()](./auth.auth.md#authusedevicelanguage) | Sets the current language to the default device/browser preference. |
@@ -88,18 +88,6 @@ The current emulator configuration (or null).
8888
readonly emulatorConfig: EmulatorConfig | null;
8989
```
9090

91-
## Auth.firebaseToken
92-
93-
The token response initialized via [exchangeToken()](./auth.md#exchangetoken_b6b1871) endpoint.
94-
95-
This field is only supported for [Auth](./auth.auth.md#auth_interface) instance that have defined [TenantConfig](./auth.tenantconfig.md#tenantconfig_interface)<!-- -->.
96-
97-
<b>Signature:</b>
98-
99-
```typescript
100-
readonly firebaseToken: FirebaseToken | null;
101-
```
102-
10391
## Auth.languageCode
10492

10593
The [Auth](./auth.auth.md#auth_interface) instance's language code.
@@ -285,6 +273,44 @@ auth.setPersistence(browserSessionPersistence);
285273

286274
```
287275

276+
## Auth.setTokenRefreshHandler()
277+
278+
Registers a handler for refreshing third-party identity provider (IDP) tokens.
279+
280+
When the Firebase access token is expired, the SDK will automatically invoke the provided handler's `refreshIdpToken()` method to obtain a new IDP token. This new token will then be exchanged for a fresh Firebase token, streamlining the authentication process.
281+
282+
<b>Signature:</b>
283+
284+
```typescript
285+
setTokenRefreshHandler(tokenRefreshHandler: TokenRefreshHandler): void;
286+
```
287+
288+
#### Parameters
289+
290+
| Parameter | Type | Description |
291+
| --- | --- | --- |
292+
| tokenRefreshHandler | [TokenRefreshHandler](./auth.tokenrefreshhandler.md#tokenrefreshhandler_interface) | An object that implements the <code>TokenRefreshHandler</code> interface, providing the logic to refresh the IDP token. |
293+
294+
<b>Returns:</b>
295+
296+
void
297+
298+
### Example
299+
300+
301+
```javascript
302+
class TokenRefreshHandlerImpl {
303+
refreshIdpToken() {
304+
// Logic to fetch a new token from your custom IDP.
305+
// Returns a Promise that resolves with a RefreshIdpTokenResult.
306+
}
307+
}
308+
309+
const tokenRefreshHandler = new TokenRefreshHandlerImpl();
310+
auth.setTokenRefreshHandler(tokenRefreshHandler);
311+
312+
```
313+
288314
## Auth.signOut()
289315

290316
Signs out the current user. This does not automatically revoke the user's ID token.

docs-devsite/auth.firebasetoken.md

Lines changed: 0 additions & 40 deletions
This file was deleted.

docs-devsite/auth.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ Firebase Authentication
118118
| [ConfirmationResult](./auth.confirmationresult.md#confirmationresult_interface) | A result from a phone number sign-in, link, or reauthenticate call. |
119119
| [Dependencies](./auth.dependencies.md#dependencies_interface) | The dependencies that can be used to initialize an [Auth](./auth.auth.md#auth_interface) instance. |
120120
| [EmulatorConfig](./auth.emulatorconfig.md#emulatorconfig_interface) | Configuration of Firebase Authentication Emulator. |
121-
| [FirebaseToken](./auth.firebasetoken.md#firebasetoken_interface) | |
122121
| [IdTokenResult](./auth.idtokenresult.md#idtokenresult_interface) | Interface representing ID token result obtained from [User.getIdTokenResult()](./auth.user.md#usergetidtokenresult)<!-- -->. |
123122
| [MultiFactorAssertion](./auth.multifactorassertion.md#multifactorassertion_interface) | The base class for asserting ownership of a second factor. |
124123
| [MultiFactorError](./auth.multifactorerror.md#multifactorerror_interface) | The error thrown when the user needs to provide a second factor to sign in successfully. |
@@ -139,7 +138,9 @@ Firebase Authentication
139138
| [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)<!-- -->. |
140139
| [ReactNativeAsyncStorage](./auth.reactnativeasyncstorage.md#reactnativeasyncstorage_interface) | Interface for a supplied <code>AsyncStorage</code>. |
141140
| [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>. |
141+
| [RefreshIdpTokenResult](./auth.refreshidptokenresult.md#refreshidptokenresult_interface) | The result of a third-party IDP token refresh operation.<!-- -->This object contains the new IDP token and the Idp Config ID of the provider that issued it. |
142142
| [TenantConfig](./auth.tenantconfig.md#tenantconfig_interface) | The tenant config that can be used to initialize a Regional [Auth](./auth.auth.md#auth_interface) instance. |
143+
| [TokenRefreshHandler](./auth.tokenrefreshhandler.md#tokenrefreshhandler_interface) | An interface for handling the refresh of Firebase tokens. |
143144
| [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)<!-- -->. |
144145
| [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. |
145146
| [User](./auth.user.md#user_interface) | A user account. |
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
# RefreshIdpTokenResult interface
13+
The result of a third-party IDP token refresh operation.
14+
15+
This object contains the new IDP token and the Idp Config ID of the provider that issued it.
16+
17+
<b>Signature:</b>
18+
19+
```typescript
20+
export interface RefreshIdpTokenResult
21+
```
22+
23+
## Properties
24+
25+
| Property | Type | Description |
26+
| --- | --- | --- |
27+
| [idpConfigId](./auth.refreshidptokenresult.md#refreshidptokenresultidpconfigid) | string | The configuration ID of the third-party identity provider. |
28+
| [idToken](./auth.refreshidptokenresult.md#refreshidptokenresultidtoken) | string | The new Id Token from the 3rd party Identity Provider. |
29+
30+
## RefreshIdpTokenResult.idpConfigId
31+
32+
The configuration ID of the third-party identity provider.
33+
34+
<b>Signature:</b>
35+
36+
```typescript
37+
idpConfigId: string;
38+
```
39+
40+
## RefreshIdpTokenResult.idToken
41+
42+
The new Id Token from the 3rd party Identity Provider.
43+
44+
<b>Signature:</b>
45+
46+
```typescript
47+
idToken: string;
48+
```
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
# TokenRefreshHandler interface
13+
An interface for handling the refresh of Firebase tokens.
14+
15+
<b>Signature:</b>
16+
17+
```typescript
18+
export interface TokenRefreshHandler
19+
```
20+
21+
## Methods
22+
23+
| Method | Description |
24+
| --- | --- |
25+
| [refreshIdpToken()](./auth.tokenrefreshhandler.md#tokenrefreshhandlerrefreshidptoken) | Refreshes the third-party IDP token.<!-- -->This method should contain the logic to obtain a new, valid IDP token from your identity provider. |
26+
27+
## TokenRefreshHandler.refreshIdpToken()
28+
29+
Refreshes the third-party IDP token.
30+
31+
This method should contain the logic to obtain a new, valid IDP token from your identity provider.
32+
33+
<b>Signature:</b>
34+
35+
```typescript
36+
refreshIdpToken(): Promise<RefreshIdpTokenResult>;
37+
```
38+
<b>Returns:</b>
39+
40+
Promise&lt;[RefreshIdpTokenResult](./auth.refreshidptokenresult.md#refreshidptokenresult_interface)<!-- -->&gt;
41+
42+
A promise that resolves with a `RefreshIdpTokenResult` object containing the new IDP token and its corresponding Idp Config ID.
43+

packages/auth/demo/src/index.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2094,15 +2094,16 @@ function initApp() {
20942094
});
20952095

20962096
const firebaseTokenStatus = document.getElementById('firebase-token-status');
2097-
setTimeout(() => {
2098-
if (regionalAuth.firebaseToken) {
2097+
setTimeout(async () => {
2098+
const firebaseToken = await regionalAuth.getFirebaseAccessToken();
2099+
if (firebaseToken) {
20992100
firebaseTokenStatus.textContent =
2100-
'✅ Firebase token is set: ' + regionalAuth.firebaseToken.token;
2101+
'✅ Firebase token is set: ' + firebaseToken;
21012102
} else {
21022103
firebaseTokenStatus.textContent =
21032104
'No CIAM token found. User not logged in.';
21042105
}
2105-
console.log('firebaseToken after delay: ', regionalAuth.firebaseToken);
2106+
console.log('firebaseToken after delay: ', firebaseToken);
21062107
}, 1000);
21072108

21082109
tempApp = initializeApp(

0 commit comments

Comments
 (0)