@@ -127,14 +127,15 @@ class AuthResourceUrlBuilder {
127127 /**
128128 * The resource URL builder constructor.
129129 *
130- * @param projectId - The resource project ID .
130+ * @param app - The app for this URL builder .
131131 * @param version - The endpoint API version.
132+ * @param emulatorHost - Optional emulator host captured at init time.
132133 * @constructor
133134 */
134- constructor ( protected app : App , protected version : string = 'v1' ) {
135- if ( useEmulator ( ) ) {
135+ constructor ( protected app : App , protected version : string = 'v1' , emHost ?: string ) {
136+ if ( emHost ) {
136137 this . urlFormat = utils . formatString ( FIREBASE_AUTH_EMULATOR_BASE_URL_FORMAT , {
137- host : emulatorHost ( )
138+ host : emHost
138139 } ) ;
139140 } else {
140141 this . urlFormat = FIREBASE_AUTH_BASE_URL_FORMAT ;
@@ -191,16 +192,17 @@ class TenantAwareAuthResourceUrlBuilder extends AuthResourceUrlBuilder {
191192 /**
192193 * The tenant aware resource URL builder constructor.
193194 *
194- * @param projectId - The resource project ID .
195+ * @param app - The app for this URL builder .
195196 * @param version - The endpoint API version.
196197 * @param tenantId - The tenant ID.
198+ * @param emHost - Optional emulator host captured at init time.
197199 * @constructor
198200 */
199- constructor ( protected app : App , protected version : string , protected tenantId : string ) {
200- super ( app , version ) ;
201- if ( useEmulator ( ) ) {
201+ constructor ( protected app : App , protected version : string , protected tenantId : string , emHost ?: string ) {
202+ super ( app , version , emHost ) ;
203+ if ( emHost ) {
202204 this . urlFormat = utils . formatString ( FIREBASE_AUTH_EMULATOR_TENANT_URL_FORMAT , {
203- host : emulatorHost ( )
205+ host : emHost
204206 } ) ;
205207 } else {
206208 this . urlFormat = FIREBASE_AUTH_TENANT_URL_FORMAT ;
@@ -229,8 +231,15 @@ class TenantAwareAuthResourceUrlBuilder extends AuthResourceUrlBuilder {
229231 */
230232class AuthHttpClient extends AuthorizedHttpClient {
231233
234+ private readonly isEmulator : boolean ;
235+
236+ constructor ( app : FirebaseApp , isEmulator : boolean ) {
237+ super ( app ) ;
238+ this . isEmulator = isEmulator ;
239+ }
240+
232241 protected getToken ( ) : Promise < string > {
233- if ( useEmulator ( ) ) {
242+ if ( this . isEmulator ) {
234243 return Promise . resolve ( 'owner' ) ;
235244 }
236245
@@ -1048,6 +1057,7 @@ const LIST_INBOUND_SAML_CONFIGS = new ApiSettings('/inboundSamlConfigs', 'GET')
10481057export abstract class AbstractAuthRequestHandler {
10491058
10501059 protected readonly httpClient : AuthorizedHttpClient ;
1060+ public readonly emulatorHostValue : string | undefined ;
10511061 private authUrlBuilder : AuthResourceUrlBuilder ;
10521062 private projectConfigUrlBuilder : AuthResourceUrlBuilder ;
10531063
@@ -1102,17 +1112,21 @@ export abstract class AbstractAuthRequestHandler {
11021112
11031113 /**
11041114 * @param app - The app used to fetch access tokens to sign API requests.
1115+ * @param emHost - Optional emulator host override. When provided (including
1116+ * null for explicitly no emulator), this value is used instead of reading
1117+ * from the FIREBASE_AUTH_EMULATOR_HOST environment variable.
11051118 * @constructor
11061119 */
1107- constructor ( protected readonly app : App ) {
1120+ constructor ( protected readonly app : App , emHost ?: string | null ) {
11081121 if ( typeof app !== 'object' || app === null || ! ( 'options' in app ) ) {
11091122 throw new FirebaseAuthError (
11101123 authClientErrorCode . INVALID_ARGUMENT ,
11111124 'First argument passed to admin.auth() must be a valid Firebase app instance.' ,
11121125 ) ;
11131126 }
11141127
1115- this . httpClient = new AuthHttpClient ( app as FirebaseApp ) ;
1128+ this . emulatorHostValue = emHost !== undefined ? ( emHost || undefined ) : emulatorHost ( ) ;
1129+ this . httpClient = new AuthHttpClient ( app as FirebaseApp , ! ! this . emulatorHostValue ) ;
11161130 }
11171131
11181132 /**
@@ -2135,21 +2149,21 @@ export class AuthRequestHandler extends AbstractAuthRequestHandler {
21352149 */
21362150 constructor ( app : App ) {
21372151 super ( app ) ;
2138- this . authResourceUrlBuilder = new AuthResourceUrlBuilder ( app , 'v2' ) ;
2152+ this . authResourceUrlBuilder = new AuthResourceUrlBuilder ( app , 'v2' , this . emulatorHostValue ) ;
21392153 }
21402154
21412155 /**
21422156 * @returns A new Auth user management resource URL builder instance.
21432157 */
21442158 protected newAuthUrlBuilder ( ) : AuthResourceUrlBuilder {
2145- return new AuthResourceUrlBuilder ( this . app , 'v1' ) ;
2159+ return new AuthResourceUrlBuilder ( this . app , 'v1' , this . emulatorHostValue ) ;
21462160 }
21472161
21482162 /**
21492163 * @returns A new project config resource URL builder instance.
21502164 */
21512165 protected newProjectConfigUrlBuilder ( ) : AuthResourceUrlBuilder {
2152- return new AuthResourceUrlBuilder ( this . app , 'v2' ) ;
2166+ return new AuthResourceUrlBuilder ( this . app , 'v2' , this . emulatorHostValue ) ;
21532167 }
21542168
21552169 /**
@@ -2306,24 +2320,25 @@ export class TenantAwareAuthRequestHandler extends AbstractAuthRequestHandler {
23062320 *
23072321 * @param app - The app used to fetch access tokens to sign API requests.
23082322 * @param tenantId - The request handler's tenant ID.
2323+ * @param emHost - Optional emulator host override captured at init time.
23092324 * @constructor
23102325 */
2311- constructor ( app : App , private readonly tenantId : string ) {
2312- super ( app ) ;
2326+ constructor ( app : App , private readonly tenantId : string , emHost ?: string | null ) {
2327+ super ( app , emHost ) ;
23132328 }
23142329
23152330 /**
23162331 * @returns A new Auth user management resource URL builder instance.
23172332 */
23182333 protected newAuthUrlBuilder ( ) : AuthResourceUrlBuilder {
2319- return new TenantAwareAuthResourceUrlBuilder ( this . app , 'v1' , this . tenantId ) ;
2334+ return new TenantAwareAuthResourceUrlBuilder ( this . app , 'v1' , this . tenantId , this . emulatorHostValue ) ;
23202335 }
23212336
23222337 /**
23232338 * @returns A new project config resource URL builder instance.
23242339 */
23252340 protected newProjectConfigUrlBuilder ( ) : AuthResourceUrlBuilder {
2326- return new TenantAwareAuthResourceUrlBuilder ( this . app , 'v2' , this . tenantId ) ;
2341+ return new TenantAwareAuthResourceUrlBuilder ( this . app , 'v2' , this . tenantId , this . emulatorHostValue ) ;
23272342 }
23282343
23292344 /**
0 commit comments