@@ -42,6 +42,7 @@ import {
4242 OIDCAuthProviderConfig , SAMLAuthProviderConfig , OIDCUpdateAuthProviderRequest ,
4343 SAMLUpdateAuthProviderRequest
4444} from './auth-config' ;
45+ import { ProjectConfig , ProjectConfigServerResponse , UpdateProjectConfigRequest } from './project-config' ;
4546
4647/** Firebase Auth request header. */
4748const FIREBASE_AUTH_HEADER = {
@@ -102,7 +103,6 @@ const FIREBASE_AUTH_TENANT_URL_FORMAT = FIREBASE_AUTH_BASE_URL_FORMAT.replace(
102103const FIREBASE_AUTH_EMULATOR_TENANT_URL_FORMAT = FIREBASE_AUTH_EMULATOR_BASE_URL_FORMAT . replace (
103104 'projects/{projectId}' , 'projects/{projectId}/tenants/{tenantId}' ) ;
104105
105-
106106/** Maximum allowed number of tenants to download at one time. */
107107const MAX_LIST_TENANT_PAGE_SIZE = 1000 ;
108108
@@ -1981,6 +1981,29 @@ export abstract class AbstractAuthRequestHandler {
19811981 }
19821982}
19831983
1984+ /** Instantiates the getConfig endpoint settings. */
1985+ const GET_PROJECT_CONFIG = new ApiSettings ( '/config' , 'GET' )
1986+ . setResponseValidator ( ( response : any ) => {
1987+ // Response should always contain at least the config name.
1988+ if ( ! validator . isNonEmptyString ( response . name ) ) {
1989+ throw new FirebaseAuthError (
1990+ AuthClientErrorCode . INTERNAL_ERROR ,
1991+ 'INTERNAL ASSERT FAILED: Unable to get project config' ,
1992+ ) ;
1993+ }
1994+ } ) ;
1995+
1996+ /** Instantiates the updateConfig endpoint settings. */
1997+ const UPDATE_PROJECT_CONFIG = new ApiSettings ( '/config?updateMask={updateMask}' , 'PATCH' )
1998+ . setResponseValidator ( ( response : any ) => {
1999+ // Response should always contain at least the config name.
2000+ if ( ! validator . isNonEmptyString ( response . name ) ) {
2001+ throw new FirebaseAuthError (
2002+ AuthClientErrorCode . INTERNAL_ERROR ,
2003+ 'INTERNAL ASSERT FAILED: Unable to update project config' ,
2004+ ) ;
2005+ }
2006+ } ) ;
19842007
19852008/** Instantiates the getTenant endpoint settings. */
19862009const GET_TENANT = new ApiSettings ( '/tenants/{tenantId}' , 'GET' )
@@ -2049,13 +2072,13 @@ const CREATE_TENANT = new ApiSettings('/tenants', 'POST')
20492072
20502073
20512074/**
2052- * Utility for sending requests to Auth server that are Auth instance related. This includes user and
2053- * tenant management related APIs. This extends the BaseFirebaseAuthRequestHandler class and defines
2075+ * Utility for sending requests to Auth server that are Auth instance related. This includes user, tenant,
2076+ * and project config management related APIs. This extends the BaseFirebaseAuthRequestHandler class and defines
20542077 * additional tenant management related APIs.
20552078 */
20562079export class AuthRequestHandler extends AbstractAuthRequestHandler {
20572080
2058- protected readonly tenantMgmtResourceBuilder : AuthResourceUrlBuilder ;
2081+ protected readonly authResourceUrlBuilder : AuthResourceUrlBuilder ;
20592082
20602083 /**
20612084 * The FirebaseAuthRequestHandler constructor used to initialize an instance using a FirebaseApp.
@@ -2065,7 +2088,7 @@ export class AuthRequestHandler extends AbstractAuthRequestHandler {
20652088 */
20662089 constructor ( app : App ) {
20672090 super ( app ) ;
2068- this . tenantMgmtResourceBuilder = new AuthResourceUrlBuilder ( app , 'v2' ) ;
2091+ this . authResourceUrlBuilder = new AuthResourceUrlBuilder ( app , 'v2' ) ;
20692092 }
20702093
20712094 /**
@@ -2082,6 +2105,35 @@ export class AuthRequestHandler extends AbstractAuthRequestHandler {
20822105 return new AuthResourceUrlBuilder ( this . app , 'v2' ) ;
20832106 }
20842107
2108+ /**
2109+ * Get the current project's config
2110+ * @returns A promise that resolves with the project config information.
2111+ */
2112+ public getProjectConfig ( ) : Promise < ProjectConfigServerResponse > {
2113+ return this . invokeRequestHandler ( this . authResourceUrlBuilder , GET_PROJECT_CONFIG , { } , { } )
2114+ . then ( ( response : any ) => {
2115+ return response as ProjectConfigServerResponse ;
2116+ } ) ;
2117+ }
2118+
2119+ /**
2120+ * Update the current project's config.
2121+ * @returns A promise that resolves with the project config information.
2122+ */
2123+ public updateProjectConfig ( options : UpdateProjectConfigRequest ) : Promise < ProjectConfigServerResponse > {
2124+ try {
2125+ const request = ProjectConfig . buildServerRequest ( options ) ;
2126+ const updateMask = utils . generateUpdateMask ( request ) ;
2127+ return this . invokeRequestHandler (
2128+ this . authResourceUrlBuilder , UPDATE_PROJECT_CONFIG , request , { updateMask : updateMask . join ( ',' ) } )
2129+ . then ( ( response : any ) => {
2130+ return response as ProjectConfigServerResponse ;
2131+ } ) ;
2132+ } catch ( e ) {
2133+ return Promise . reject ( e ) ;
2134+ }
2135+ }
2136+
20852137 /**
20862138 * Looks up a tenant by tenant ID.
20872139 *
@@ -2092,7 +2144,7 @@ export class AuthRequestHandler extends AbstractAuthRequestHandler {
20922144 if ( ! validator . isNonEmptyString ( tenantId ) ) {
20932145 return Promise . reject ( new FirebaseAuthError ( AuthClientErrorCode . INVALID_TENANT_ID ) ) ;
20942146 }
2095- return this . invokeRequestHandler ( this . tenantMgmtResourceBuilder , GET_TENANT , { } , { tenantId } )
2147+ return this . invokeRequestHandler ( this . authResourceUrlBuilder , GET_TENANT , { } , { tenantId } )
20962148 . then ( ( response : any ) => {
20972149 return response as TenantServerResponse ;
20982150 } ) ;
@@ -2122,7 +2174,7 @@ export class AuthRequestHandler extends AbstractAuthRequestHandler {
21222174 if ( typeof request . pageToken === 'undefined' ) {
21232175 delete request . pageToken ;
21242176 }
2125- return this . invokeRequestHandler ( this . tenantMgmtResourceBuilder , LIST_TENANTS , request )
2177+ return this . invokeRequestHandler ( this . authResourceUrlBuilder , LIST_TENANTS , request )
21262178 . then ( ( response : any ) => {
21272179 if ( ! response . tenants ) {
21282180 response . tenants = [ ] ;
@@ -2142,7 +2194,7 @@ export class AuthRequestHandler extends AbstractAuthRequestHandler {
21422194 if ( ! validator . isNonEmptyString ( tenantId ) ) {
21432195 return Promise . reject ( new FirebaseAuthError ( AuthClientErrorCode . INVALID_TENANT_ID ) ) ;
21442196 }
2145- return this . invokeRequestHandler ( this . tenantMgmtResourceBuilder , DELETE_TENANT , undefined , { tenantId } )
2197+ return this . invokeRequestHandler ( this . authResourceUrlBuilder , DELETE_TENANT , undefined , { tenantId } )
21462198 . then ( ( ) => {
21472199 // Return nothing.
21482200 } ) ;
@@ -2158,7 +2210,7 @@ export class AuthRequestHandler extends AbstractAuthRequestHandler {
21582210 try {
21592211 // Construct backend request.
21602212 const request = Tenant . buildServerRequest ( tenantOptions , true ) ;
2161- return this . invokeRequestHandler ( this . tenantMgmtResourceBuilder , CREATE_TENANT , request )
2213+ return this . invokeRequestHandler ( this . authResourceUrlBuilder , CREATE_TENANT , request )
21622214 . then ( ( response : any ) => {
21632215 return response as TenantServerResponse ;
21642216 } ) ;
@@ -2184,7 +2236,7 @@ export class AuthRequestHandler extends AbstractAuthRequestHandler {
21842236 // Do not traverse deep into testPhoneNumbers. The entire content should be replaced
21852237 // and not just specific phone numbers.
21862238 const updateMask = utils . generateUpdateMask ( request , [ 'testPhoneNumbers' ] ) ;
2187- return this . invokeRequestHandler ( this . tenantMgmtResourceBuilder , UPDATE_TENANT , request ,
2239+ return this . invokeRequestHandler ( this . authResourceUrlBuilder , UPDATE_TENANT , request ,
21882240 { tenantId, updateMask : updateMask . join ( ',' ) } )
21892241 . then ( ( response : any ) => {
21902242 return response as TenantServerResponse ;
0 commit comments