17
17
import * as validator from '../utils/validator' ;
18
18
import { deepCopy } from '../utils/deep-copy' ;
19
19
import { AuthClientErrorCode , FirebaseAuthError } from '../utils/error' ;
20
+ import { auth } from './index' ;
21
+
22
+ import MultiFactorConfigInterface = auth . MultiFactorConfig ;
23
+ import MultiFactorConfigState = auth . MultiFactorConfigState ;
24
+ import AuthFactorType = auth . AuthFactorType ;
25
+ import EmailSignInProviderConfig = auth . EmailSignInProviderConfig ;
26
+ import OIDCAuthProviderConfig = auth . OIDCAuthProviderConfig ;
27
+ import SAMLAuthProviderConfig = auth . SAMLAuthProviderConfig ;
20
28
21
29
/** A maximum of 10 test phone number / code pairs can be configured. */
22
30
export const MAXIMUM_TEST_PHONE_NUMBERS = 10 ;
23
31
24
- /** The filter interface used for listing provider configurations. */
25
- export interface AuthProviderConfigFilter {
26
- type : 'saml' | 'oidc' ;
27
- maxResults ?: number ;
28
- pageToken ?: string ;
29
- }
30
-
31
- /** The base Auth provider configuration interface. */
32
- export interface AuthProviderConfig {
33
- providerId : string ;
34
- displayName ?: string ;
35
- enabled : boolean ;
36
- }
37
-
38
- /** The OIDC Auth provider configuration interface. */
39
- export interface OIDCAuthProviderConfig extends AuthProviderConfig {
40
- clientId : string ;
41
- issuer : string ;
42
- }
43
-
44
- /** The SAML Auth provider configuration interface. */
45
- export interface SAMLAuthProviderConfig extends AuthProviderConfig {
46
- idpEntityId : string ;
47
- ssoURL : string ;
48
- x509Certificates : string [ ] ;
49
- rpEntityId : string ;
50
- callbackURL ?: string ;
51
- enableRequestSigning ?: boolean ;
52
- }
53
-
54
32
/** The server side SAML configuration request interface. */
55
33
export interface SAMLConfigServerRequest {
56
34
idpConfig ?: {
@@ -111,107 +89,39 @@ export interface OIDCConfigServerResponse {
111
89
enabled ?: boolean ;
112
90
}
113
91
114
- /** The public API response interface for listing provider configs. */
115
- export interface ListProviderConfigResults {
116
- providerConfigs : AuthProviderConfig [ ] ;
117
- pageToken ?: string ;
118
- }
119
-
120
- /** The public API request interface for updating a SAML Auth provider. */
121
- export interface SAMLUpdateAuthProviderRequest {
122
- idpEntityId ?: string ;
123
- ssoURL ?: string ;
124
- x509Certificates ?: string [ ] ;
125
- rpEntityId ?: string ;
126
- callbackURL ?: string ;
127
- enableRequestSigning ?: boolean ;
128
- enabled ?: boolean ;
129
- displayName ?: string ;
130
- }
131
-
132
- /** The generic request interface for updating/creating a SAML Auth provider. */
133
- export interface SAMLAuthProviderRequest extends SAMLUpdateAuthProviderRequest {
134
- providerId ?: string ;
135
- }
136
-
137
- /** The public API request interface for updating an OIDC Auth provider. */
138
- export interface OIDCUpdateAuthProviderRequest {
139
- clientId ?: string ;
140
- issuer ?: string ;
141
- enabled ?: boolean ;
142
- displayName ?: string ;
143
- }
144
-
145
- /** The generic request interface for updating/creating an OIDC Auth provider. */
146
- export interface OIDCAuthProviderRequest extends OIDCUpdateAuthProviderRequest {
147
- providerId ?: string ;
148
- }
149
-
150
- /** The public API request interface for updating a generic Auth provider. */
151
- export type UpdateAuthProviderRequest = SAMLUpdateAuthProviderRequest | OIDCUpdateAuthProviderRequest ;
152
-
153
- /** The email provider configuration interface. */
154
- export interface EmailSignInProviderConfig {
155
- enabled ?: boolean ;
156
- passwordRequired ?: boolean ; // In the backend API, default is true if not provided
157
- }
158
-
159
92
/** The server side email configuration request interface. */
160
93
export interface EmailSignInConfigServerRequest {
161
94
allowPasswordSignup ?: boolean ;
162
95
enableEmailLinkSignin ?: boolean ;
163
96
}
164
97
165
- /** Identifies the public second factor type. */
166
- export type AuthFactorType = 'phone' ;
167
-
168
98
/** Identifies the server side second factor type. */
169
- export type AuthFactorServerType = 'PHONE_SMS' ;
99
+ type AuthFactorServerType = 'PHONE_SMS' ;
170
100
171
101
/** Client Auth factor type to server auth factor type mapping. */
172
- export const AUTH_FACTOR_CLIENT_TO_SERVER_TYPE : { [ key : string ] : AuthFactorServerType } = {
102
+ const AUTH_FACTOR_CLIENT_TO_SERVER_TYPE : { [ key : string ] : AuthFactorServerType } = {
173
103
phone : 'PHONE_SMS' ,
174
104
} ;
175
105
176
106
/** Server Auth factor type to client auth factor type mapping. */
177
- export const AUTH_FACTOR_SERVER_TO_CLIENT_TYPE : { [ key : string ] : AuthFactorType } =
107
+ const AUTH_FACTOR_SERVER_TO_CLIENT_TYPE : { [ key : string ] : AuthFactorType } =
178
108
Object . keys ( AUTH_FACTOR_CLIENT_TO_SERVER_TYPE )
179
109
. reduce ( ( res : { [ key : string ] : AuthFactorType } , key ) => {
180
110
res [ AUTH_FACTOR_CLIENT_TO_SERVER_TYPE [ key ] ] = key as AuthFactorType ;
181
111
return res ;
182
112
} , { } ) ;
183
113
184
- /** Identifies a multi-factor configuration state. */
185
- export type MultiFactorConfigState = 'ENABLED' | 'DISABLED' ;
186
-
187
- /**
188
- * Public API interface representing a multi-factor configuration.
189
- */
190
- export interface MultiFactorConfig {
191
- /**
192
- * The multi-factor config state.
193
- */
194
- state : MultiFactorConfigState ;
195
-
196
- /**
197
- * The list of identifiers for enabled second factors.
198
- * Currently only ‘phone’ is supported.
199
- */
200
- factorIds ?: AuthFactorType [ ] ;
201
- }
202
-
203
114
/** Server side multi-factor configuration. */
204
115
export interface MultiFactorAuthServerConfig {
205
116
state ?: MultiFactorConfigState ;
206
117
enabledProviders ?: AuthFactorServerType [ ] ;
207
118
}
208
119
209
-
210
120
/**
211
121
* Defines the multi-factor config class used to convert client side MultiFactorConfig
212
122
* to a format that is understood by the Auth server.
213
123
*/
214
- export class MultiFactorAuthConfig implements MultiFactorConfig {
124
+ export class MultiFactorAuthConfig implements MultiFactorConfigInterface {
215
125
public readonly state : MultiFactorConfigState ;
216
126
public readonly factorIds : AuthFactorType [ ] ;
217
127
@@ -222,7 +132,7 @@ export class MultiFactorAuthConfig implements MultiFactorConfig {
222
132
* @param options The options object to convert to a server request.
223
133
* @return The resulting server request.
224
134
*/
225
- public static buildServerRequest ( options : MultiFactorConfig ) : MultiFactorAuthServerConfig {
135
+ public static buildServerRequest ( options : MultiFactorConfigInterface ) : MultiFactorAuthServerConfig {
226
136
const request : MultiFactorAuthServerConfig = { } ;
227
137
MultiFactorAuthConfig . validate ( options ) ;
228
138
if ( Object . prototype . hasOwnProperty . call ( options , 'state' ) ) {
@@ -248,7 +158,7 @@ export class MultiFactorAuthConfig implements MultiFactorConfig {
248
158
*
249
159
* @param options The options object to validate.
250
160
*/
251
- private static validate ( options : MultiFactorConfig ) : void {
161
+ private static validate ( options : MultiFactorConfigInterface ) : void {
252
162
const validKeys = {
253
163
state : true ,
254
164
factorIds : true ,
@@ -492,7 +402,7 @@ export class SAMLConfig implements SAMLAuthProviderConfig {
492
402
* @return {?SAMLConfigServerRequest } The resulting server request or null if not valid.
493
403
*/
494
404
public static buildServerRequest (
495
- options : SAMLAuthProviderRequest ,
405
+ options : Partial < SAMLAuthProviderConfig > ,
496
406
ignoreMissingFields = false ) : SAMLConfigServerRequest | null {
497
407
const makeRequest = validator . isNonNullObject ( options ) &&
498
408
( options . providerId || ignoreMissingFields ) ;
@@ -509,7 +419,7 @@ export class SAMLConfig implements SAMLAuthProviderConfig {
509
419
request . idpConfig = {
510
420
idpEntityId : options . idpEntityId ,
511
421
ssoUrl : options . ssoURL ,
512
- signRequest : options . enableRequestSigning ,
422
+ signRequest : ( options as any ) . enableRequestSigning ,
513
423
idpCertificates : typeof options . x509Certificates === 'undefined' ? undefined : [ ] ,
514
424
} ;
515
425
if ( options . x509Certificates ) {
@@ -557,7 +467,7 @@ export class SAMLConfig implements SAMLAuthProviderConfig {
557
467
* @param {SAMLAuthProviderRequest } options The options object to validate.
558
468
* @param {boolean= } ignoreMissingFields Whether to ignore missing fields.
559
469
*/
560
- public static validate ( options : SAMLAuthProviderRequest , ignoreMissingFields = false ) : void {
470
+ public static validate ( options : Partial < SAMLAuthProviderConfig > , ignoreMissingFields = false ) : void {
561
471
const validKeys = {
562
472
enabled : true ,
563
473
displayName : true ,
@@ -643,8 +553,8 @@ export class SAMLConfig implements SAMLAuthProviderConfig {
643
553
) ;
644
554
}
645
555
} ) ;
646
- if ( typeof options . enableRequestSigning !== 'undefined' &&
647
- ! validator . isBoolean ( options . enableRequestSigning ) ) {
556
+ if ( typeof ( options as any ) . enableRequestSigning !== 'undefined' &&
557
+ ! validator . isBoolean ( ( options as any ) . enableRequestSigning ) ) {
648
558
throw new FirebaseAuthError (
649
559
AuthClientErrorCode . INVALID_CONFIG ,
650
560
'"SAMLAuthProviderConfig.enableRequestSigning" must be a boolean.' ,
@@ -714,8 +624,8 @@ export class SAMLConfig implements SAMLAuthProviderConfig {
714
624
this . displayName = response . displayName ;
715
625
}
716
626
717
- /** @return { SAMLAuthProviderConfig } The plain object representation of the SAMLConfig. */
718
- public toJSON ( ) : SAMLAuthProviderConfig {
627
+ /** @return The plain object representation of the SAMLConfig. */
628
+ public toJSON ( ) : object {
719
629
return {
720
630
enabled : this . enabled ,
721
631
displayName : this . displayName ,
@@ -747,12 +657,12 @@ export class OIDCConfig implements OIDCAuthProviderConfig {
747
657
* Throws an error if validation fails. If the request is not a OIDCConfig request,
748
658
* returns null.
749
659
*
750
- * @param { OIDCAuthProviderRequest } options The options object to convert to a server request.
751
- * @param { boolean= } ignoreMissingFields Whether to ignore missing fields.
752
- * @return { ?OIDCConfigServerRequest } The resulting server request or null if not valid.
660
+ * @param options The options object to convert to a server request.
661
+ * @param ignoreMissingFields Whether to ignore missing fields.
662
+ * @return The resulting server request or null if not valid.
753
663
*/
754
664
public static buildServerRequest (
755
- options : OIDCAuthProviderRequest ,
665
+ options : Partial < OIDCAuthProviderConfig > ,
756
666
ignoreMissingFields = false ) : OIDCConfigServerRequest | null {
757
667
const makeRequest = validator . isNonNullObject ( options ) &&
758
668
( options . providerId || ignoreMissingFields ) ;
@@ -795,10 +705,10 @@ export class OIDCConfig implements OIDCAuthProviderConfig {
795
705
/**
796
706
* Validates the OIDCConfig options object. Throws an error on failure.
797
707
*
798
- * @param { OIDCAuthProviderRequest } options The options object to validate.
799
- * @param { boolean= } ignoreMissingFields Whether to ignore missing fields.
708
+ * @param options The options object to validate.
709
+ * @param ignoreMissingFields Whether to ignore missing fields.
800
710
*/
801
- public static validate ( options : OIDCAuthProviderRequest , ignoreMissingFields = false ) : void {
711
+ public static validate ( options : Partial < OIDCAuthProviderConfig > , ignoreMissingFields = false ) : void {
802
712
const validKeys = {
803
713
enabled : true ,
804
714
displayName : true ,
0 commit comments