Draft
Show file tree
Hide file tree
Changes from 1 commit
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Failed to load files.
PrevPrevious commit
Exchange Token interop changes
  • Loading branch information
@mansisampat
mansisampat committedMay 22, 2025
commit 14eb3932773565246a8f6ea028b24c71d5452228
Original file line numberDiff line numberDiff line change
Expand Up@@ -28,7 +28,7 @@ export interface ExchangeTokenRequest {

export interface ExchangeTokenRespose {
accessToken: string;
expiresIn: string;
expiresInSec: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not store this as a Number instead of string?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

export async function exchangeToken(
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -629,6 +629,11 @@ export class AuthImpl implements AuthInternal, _FirebaseService {
}
}

async getTokenForRegionalAuth():
Promise<string> {
if (Date.now() > this.tokenResponse?.expiresIn)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks incomplete

}

toJSON(): object {
return {
apiKey: this.config.apiKey,
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -43,6 +43,9 @@ export class AuthInterop implements FirebaseAuthInternal {
): Promise<{ accessToken: string } | null> {
this.assertAuthConfigured();
await this.auth._initializationPromise;
if (this.auth.tenantConfig) {
return this.getTokenRegionalAuth();
}
if (!this.auth.currentUser) {
return null;
}
Expand All@@ -51,6 +54,23 @@ export class AuthInterop implements FirebaseAuthInternal {
return { accessToken };
}

async getTokenRegionalAuth() :
Promise<{ accessToken: string } | null> {
this.assertRegionalAuthConfigured();
if (!this.auth.tokenResponse) {
return null;
}

if (!this.auth.tokenResponse.expirationTime ||
Date.now() > this.auth.tokenResponse.expirationTime) {
await this.auth._updateTokenResponse(null);
return null;
}

const accessToken = await this.auth.tokenResponse.token;
return { accessToken };
}

addAuthTokenListener(listener: TokenListener): void {
this.assertAuthConfigured();
if (this.internalListeners.has(listener)) {
Expand DownExpand Up@@ -85,6 +105,10 @@ export class AuthInterop implements FirebaseAuthInternal {
);
}

private assertRegionalAuthConfigured(): void {
_assert(this.auth.tenantConfig, AuthErrorCode.OPERATION_NOT_ALLOWED);
}

private updateProactiveRefresh(): void {
if (this.internalListeners.size > 0) {
this.auth._startProactiveRefresh();
Expand Down
Loading