Skip to content

Commit 14eb393

Browse files
committed
Exchange Token interop changes
1 parent 7ca7909 commit 14eb393

File tree

5 files changed

+33
-4
lines changed

5 files changed

+33
-4
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export interface ExchangeTokenRequest {
2828

2929
export interface ExchangeTokenRespose {
3030
accessToken: string;
31-
expiresIn: string;
31+
expiresInSec: string;
3232
}
3333

3434
export async function exchangeToken(

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,11 @@ export class AuthImpl implements AuthInternal, _FirebaseService {
629629
}
630630
}
631631

632+
async getTokenForRegionalAuth():
633+
Promise<string> {
634+
if (Date.now() > this.tokenResponse?.expiresIn)
635+
}
636+
632637
toJSON(): object {
633638
return {
634639
apiKey: this.config.apiKey,

packages/auth/src/core/auth/firebase_internal.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ export class AuthInterop implements FirebaseAuthInternal {
4343
): Promise<{ accessToken: string } | null> {
4444
this.assertAuthConfigured();
4545
await this.auth._initializationPromise;
46+
if (this.auth.tenantConfig) {
47+
return this.getTokenRegionalAuth();
48+
}
4649
if (!this.auth.currentUser) {
4750
return null;
4851
}
@@ -51,6 +54,23 @@ export class AuthInterop implements FirebaseAuthInternal {
5154
return { accessToken };
5255
}
5356

57+
async getTokenRegionalAuth() :
58+
Promise<{ accessToken: string } | null> {
59+
this.assertRegionalAuthConfigured();
60+
if (!this.auth.tokenResponse) {
61+
return null;
62+
}
63+
64+
if (!this.auth.tokenResponse.expirationTime ||
65+
Date.now() > this.auth.tokenResponse.expirationTime) {
66+
await this.auth._updateTokenResponse(null);
67+
return null;
68+
}
69+
70+
const accessToken = await this.auth.tokenResponse.token;
71+
return { accessToken };
72+
}
73+
5474
addAuthTokenListener(listener: TokenListener): void {
5575
this.assertAuthConfigured();
5676
if (this.internalListeners.has(listener)) {
@@ -85,6 +105,10 @@ export class AuthInterop implements FirebaseAuthInternal {
85105
);
86106
}
87107

108+
private assertRegionalAuthConfigured(): void {
109+
_assert(this.auth.tenantConfig, AuthErrorCode.OPERATION_NOT_ALLOWED);
110+
}
111+
88112
private updateProactiveRefresh(): void {
89113
if (this.internalListeners.size > 0) {
90114
this.auth._startProactiveRefresh();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export async function exchangeToken(
5757
if (token) {
5858
await authInternal._updateTokenResponse({
5959
token: token.accessToken,
60-
expiresIn: token.expiresIn
60+
expirationTime: Date.now() + Number(token.expiresInSec) * 1000
6161
});
6262
}
6363
return token.accessToken;

packages/auth/src/model/public_types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -982,8 +982,8 @@ export interface ReactNativeAsyncStorage {
982982
export interface TokenResponse {
983983
// The firebase access token (JWT signed by Firebase Auth).
984984
readonly token: string;
985-
// The time in seconds when the access token expires.
986-
readonly expiresIn: string;
985+
// The time when the access token expires.
986+
readonly expirationTime: number;
987987
}
988988

989989
/**

0 commit comments

Comments
 (0)