@@ -149,6 +149,115 @@ export interface OIDCAuthProviderRequest extends OIDCUpdateAuthProviderRequest {
149149/** The public API request interface for updating a generic Auth provider. */
150150export type UpdateAuthProviderRequest = SAMLUpdateAuthProviderRequest | OIDCUpdateAuthProviderRequest ;
151151
152+ /** The email provider configuration interface. */
153+ export interface EmailSignInProviderConfig {
154+ enabled ?: boolean ;
155+ passwordRequired ?: boolean ; // In the backend API, default is true if not provided
156+ }
157+
158+ /** The server side email configuration request interface. */
159+ export interface EmailSignInConfigServerRequest {
160+ allowPasswordSignup ?: boolean ;
161+ enableEmailLinkSignin ?: boolean ;
162+ }
163+
164+
165+ /**
166+ * Defines the email sign-in config class used to convert client side EmailSignInConfig
167+ * to a format that is understood by the Auth server.
168+ */
169+ export class EmailSignInConfig implements EmailSignInProviderConfig {
170+ public readonly enabled ?: boolean ;
171+ public readonly passwordRequired ?: boolean ;
172+
173+ /**
174+ * Static method to convert a client side request to a EmailSignInConfigServerRequest.
175+ * Throws an error if validation fails.
176+ *
177+ * @param {any } options The options object to convert to a server request.
178+ * @return {EmailSignInConfigServerRequest } The resulting server request.
179+ */
180+ public static buildServerRequest ( options : EmailSignInProviderConfig ) : EmailSignInConfigServerRequest {
181+ const request : EmailSignInConfigServerRequest = { } ;
182+ EmailSignInConfig . validate ( options ) ;
183+ if ( options . hasOwnProperty ( 'enabled' ) ) {
184+ request . allowPasswordSignup = options . enabled ;
185+ }
186+ if ( options . hasOwnProperty ( 'passwordRequired' ) ) {
187+ request . enableEmailLinkSignin = ! options . passwordRequired ;
188+ }
189+ return request ;
190+ }
191+
192+ /**
193+ * Validates the EmailSignInConfig options object. Throws an error on failure.
194+ *
195+ * @param {any } options The options object to validate.
196+ */
197+ private static validate ( options : { [ key : string ] : any } ) {
198+ // TODO: Validate the request.
199+ const validKeys = {
200+ enabled : true ,
201+ passwordRequired : true ,
202+ } ;
203+ if ( ! validator . isNonNullObject ( options ) ) {
204+ throw new FirebaseAuthError (
205+ AuthClientErrorCode . INVALID_ARGUMENT ,
206+ '"EmailSignInConfig" must be a non-null object.' ,
207+ ) ;
208+ }
209+ // Check for unsupported top level attributes.
210+ for ( const key in options ) {
211+ if ( ! ( key in validKeys ) ) {
212+ throw new FirebaseAuthError (
213+ AuthClientErrorCode . INVALID_ARGUMENT ,
214+ `"${ key } " is not a valid EmailSignInConfig parameter.` ,
215+ ) ;
216+ }
217+ }
218+ // Validate content.
219+ if ( typeof options . enabled !== 'undefined' &&
220+ ! validator . isBoolean ( options . enabled ) ) {
221+ throw new FirebaseAuthError (
222+ AuthClientErrorCode . INVALID_ARGUMENT ,
223+ '"EmailSignInConfig.enabled" must be a boolean.' ,
224+ ) ;
225+ }
226+ if ( typeof options . passwordRequired !== 'undefined' &&
227+ ! validator . isBoolean ( options . passwordRequired ) ) {
228+ throw new FirebaseAuthError (
229+ AuthClientErrorCode . INVALID_ARGUMENT ,
230+ '"EmailSignInConfig.passwordRequired" must be a boolean.' ,
231+ ) ;
232+ }
233+ }
234+
235+ /**
236+ * The EmailSignInConfig constructor.
237+ *
238+ * @param {any } response The server side response used to initialize the
239+ * EmailSignInConfig object.
240+ * @constructor
241+ */
242+ constructor ( response : { [ key : string ] : any } ) {
243+ if ( typeof response . allowPasswordSignup === 'undefined' ) {
244+ throw new FirebaseAuthError (
245+ AuthClientErrorCode . INTERNAL_ERROR ,
246+ 'INTERNAL ASSERT FAILED: Invalid email sign-in configuration response' ) ;
247+ }
248+ this . enabled = response . allowPasswordSignup ;
249+ this . passwordRequired = ! response . enableEmailLinkSignin ;
250+ }
251+
252+ /** @return {object } The plain object representation of the email sign-in config. */
253+ public toJSON ( ) : object {
254+ return {
255+ enabled : this . enabled ,
256+ passwordRequired : this . passwordRequired ,
257+ } ;
258+ }
259+ }
260+
152261
153262/**
154263 * Defines the SAMLConfig class used to convert a client side configuration to its
@@ -367,24 +476,24 @@ export class SAMLConfig implements SAMLAuthProviderConfig {
367476 AuthClientErrorCode . INTERNAL_ERROR ,
368477 'INTERNAL ASSERT FAILED: Invalid SAML configuration response' ) ;
369478 }
370- utils . addReadonlyGetter ( this , ' providerId' , SAMLConfig . getProviderIdFromResourceName ( response . name ) ) ;
479+ this . providerId = SAMLConfig . getProviderIdFromResourceName ( response . name ) ;
371480 // RP config.
372- utils . addReadonlyGetter ( this , ' rpEntityId' , response . spConfig . spEntityId ) ;
373- utils . addReadonlyGetter ( this , ' callbackURL' , response . spConfig . callbackUri ) ;
481+ this . rpEntityId = response . spConfig . spEntityId ;
482+ this . callbackURL = response . spConfig . callbackUri ;
374483 // IdP config.
375- utils . addReadonlyGetter ( this , ' idpEntityId' , response . idpConfig . idpEntityId ) ;
376- utils . addReadonlyGetter ( this , ' ssoURL' , response . idpConfig . ssoUrl ) ;
377- utils . addReadonlyGetter ( this , ' enableRequestSigning' , ! ! response . idpConfig . signRequest ) ;
484+ this . idpEntityId = response . idpConfig . idpEntityId ;
485+ this . ssoURL = response . idpConfig . ssoUrl ;
486+ this . enableRequestSigning = ! ! response . idpConfig . signRequest ;
378487 const x509Certificates : string [ ] = [ ] ;
379488 for ( const cert of ( response . idpConfig . idpCertificates || [ ] ) ) {
380489 if ( cert . x509Certificate ) {
381490 x509Certificates . push ( cert . x509Certificate ) ;
382491 }
383492 }
384- utils . addReadonlyGetter ( this , ' x509Certificates' , x509Certificates ) ;
493+ this . x509Certificates = x509Certificates ;
385494 // When enabled is undefined, it takes its default value of false.
386- utils . addReadonlyGetter ( this , ' enabled' , ! ! response . enabled ) ;
387- utils . addReadonlyGetter ( this , ' displayName' , response . displayName ) ;
495+ this . enabled = ! ! response . enabled ;
496+ this . displayName = response . displayName ;
388497 }
389498
390499 /** @return {SAMLAuthProviderConfig } The plain object representation of the SAMLConfig. */
@@ -555,12 +664,12 @@ export class OIDCConfig implements OIDCAuthProviderConfig {
555664 AuthClientErrorCode . INTERNAL_ERROR ,
556665 'INTERNAL ASSERT FAILED: Invalid OIDC configuration response' ) ;
557666 }
558- utils . addReadonlyGetter ( this , ' providerId' , OIDCConfig . getProviderIdFromResourceName ( response . name ) ) ;
559- utils . addReadonlyGetter ( this , ' clientId' , response . clientId ) ;
560- utils . addReadonlyGetter ( this , ' issuer' , response . issuer ) ;
667+ this . providerId = OIDCConfig . getProviderIdFromResourceName ( response . name ) ;
668+ this . clientId = response . clientId ;
669+ this . issuer = response . issuer ;
561670 // When enabled is undefined, it takes its default value of false.
562- utils . addReadonlyGetter ( this , ' enabled' , ! ! response . enabled ) ;
563- utils . addReadonlyGetter ( this , ' displayName' , response . displayName ) ;
671+ this . enabled = ! ! response . enabled ;
672+ this . displayName = response . displayName ;
564673 }
565674
566675 /** @return {OIDCAuthProviderConfig } The plain object representation of the OIDCConfig. */
0 commit comments