@@ -42,6 +42,7 @@ import {
42
42
OIDCAuthProviderConfig , SAMLAuthProviderConfig , OIDCUpdateAuthProviderRequest ,
43
43
SAMLUpdateAuthProviderRequest
44
44
} from './auth-config' ;
45
+ import { ProjectConfig , ProjectConfigServerResponse , UpdateProjectConfigRequest } from './project-config' ;
45
46
46
47
/** Firebase Auth request header. */
47
48
const FIREBASE_AUTH_HEADER = {
@@ -102,7 +103,6 @@ const FIREBASE_AUTH_TENANT_URL_FORMAT = FIREBASE_AUTH_BASE_URL_FORMAT.replace(
102
103
const FIREBASE_AUTH_EMULATOR_TENANT_URL_FORMAT = FIREBASE_AUTH_EMULATOR_BASE_URL_FORMAT . replace (
103
104
'projects/{projectId}' , 'projects/{projectId}/tenants/{tenantId}' ) ;
104
105
105
-
106
106
/** Maximum allowed number of tenants to download at one time. */
107
107
const MAX_LIST_TENANT_PAGE_SIZE = 1000 ;
108
108
@@ -1981,6 +1981,29 @@ export abstract class AbstractAuthRequestHandler {
1981
1981
}
1982
1982
}
1983
1983
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
+ } ) ;
1984
2007
1985
2008
/** Instantiates the getTenant endpoint settings. */
1986
2009
const GET_TENANT = new ApiSettings ( '/tenants/{tenantId}' , 'GET' )
@@ -2049,13 +2072,13 @@ const CREATE_TENANT = new ApiSettings('/tenants', 'POST')
2049
2072
2050
2073
2051
2074
/**
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
2054
2077
* additional tenant management related APIs.
2055
2078
*/
2056
2079
export class AuthRequestHandler extends AbstractAuthRequestHandler {
2057
2080
2058
- protected readonly tenantMgmtResourceBuilder : AuthResourceUrlBuilder ;
2081
+ protected readonly authResourceUrlBuilder : AuthResourceUrlBuilder ;
2059
2082
2060
2083
/**
2061
2084
* The FirebaseAuthRequestHandler constructor used to initialize an instance using a FirebaseApp.
@@ -2065,7 +2088,7 @@ export class AuthRequestHandler extends AbstractAuthRequestHandler {
2065
2088
*/
2066
2089
constructor ( app : App ) {
2067
2090
super ( app ) ;
2068
- this . tenantMgmtResourceBuilder = new AuthResourceUrlBuilder ( app , 'v2' ) ;
2091
+ this . authResourceUrlBuilder = new AuthResourceUrlBuilder ( app , 'v2' ) ;
2069
2092
}
2070
2093
2071
2094
/**
@@ -2082,6 +2105,35 @@ export class AuthRequestHandler extends AbstractAuthRequestHandler {
2082
2105
return new AuthResourceUrlBuilder ( this . app , 'v2' ) ;
2083
2106
}
2084
2107
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
+
2085
2137
/**
2086
2138
* Looks up a tenant by tenant ID.
2087
2139
*
@@ -2092,7 +2144,7 @@ export class AuthRequestHandler extends AbstractAuthRequestHandler {
2092
2144
if ( ! validator . isNonEmptyString ( tenantId ) ) {
2093
2145
return Promise . reject ( new FirebaseAuthError ( AuthClientErrorCode . INVALID_TENANT_ID ) ) ;
2094
2146
}
2095
- return this . invokeRequestHandler ( this . tenantMgmtResourceBuilder , GET_TENANT , { } , { tenantId } )
2147
+ return this . invokeRequestHandler ( this . authResourceUrlBuilder , GET_TENANT , { } , { tenantId } )
2096
2148
. then ( ( response : any ) => {
2097
2149
return response as TenantServerResponse ;
2098
2150
} ) ;
@@ -2122,7 +2174,7 @@ export class AuthRequestHandler extends AbstractAuthRequestHandler {
2122
2174
if ( typeof request . pageToken === 'undefined' ) {
2123
2175
delete request . pageToken ;
2124
2176
}
2125
- return this . invokeRequestHandler ( this . tenantMgmtResourceBuilder , LIST_TENANTS , request )
2177
+ return this . invokeRequestHandler ( this . authResourceUrlBuilder , LIST_TENANTS , request )
2126
2178
. then ( ( response : any ) => {
2127
2179
if ( ! response . tenants ) {
2128
2180
response . tenants = [ ] ;
@@ -2142,7 +2194,7 @@ export class AuthRequestHandler extends AbstractAuthRequestHandler {
2142
2194
if ( ! validator . isNonEmptyString ( tenantId ) ) {
2143
2195
return Promise . reject ( new FirebaseAuthError ( AuthClientErrorCode . INVALID_TENANT_ID ) ) ;
2144
2196
}
2145
- return this . invokeRequestHandler ( this . tenantMgmtResourceBuilder , DELETE_TENANT , undefined , { tenantId } )
2197
+ return this . invokeRequestHandler ( this . authResourceUrlBuilder , DELETE_TENANT , undefined , { tenantId } )
2146
2198
. then ( ( ) => {
2147
2199
// Return nothing.
2148
2200
} ) ;
@@ -2158,7 +2210,7 @@ export class AuthRequestHandler extends AbstractAuthRequestHandler {
2158
2210
try {
2159
2211
// Construct backend request.
2160
2212
const request = Tenant . buildServerRequest ( tenantOptions , true ) ;
2161
- return this . invokeRequestHandler ( this . tenantMgmtResourceBuilder , CREATE_TENANT , request )
2213
+ return this . invokeRequestHandler ( this . authResourceUrlBuilder , CREATE_TENANT , request )
2162
2214
. then ( ( response : any ) => {
2163
2215
return response as TenantServerResponse ;
2164
2216
} ) ;
@@ -2184,7 +2236,7 @@ export class AuthRequestHandler extends AbstractAuthRequestHandler {
2184
2236
// Do not traverse deep into testPhoneNumbers. The entire content should be replaced
2185
2237
// and not just specific phone numbers.
2186
2238
const updateMask = utils . generateUpdateMask ( request , [ 'testPhoneNumbers' ] ) ;
2187
- return this . invokeRequestHandler ( this . tenantMgmtResourceBuilder , UPDATE_TENANT , request ,
2239
+ return this . invokeRequestHandler ( this . authResourceUrlBuilder , UPDATE_TENANT , request ,
2188
2240
{ tenantId, updateMask : updateMask . join ( ',' ) } )
2189
2241
. then ( ( response : any ) => {
2190
2242
return response as TenantServerResponse ;
0 commit comments