Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
EmailPrivacy Config definition
  • Loading branch information
pragatimodi committed May 28, 2023
commit c9d328ccf7434b7c8c2baf62e26cd71feb6adf63
73 changes: 60 additions & 13 deletions src/auth/auth-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -509,14 +509,14 @@ export interface MultiFactorConfig {
factorIds?: AuthFactorType[];

/**
* A list of multi-factor provider configurations.
* A list of multi-factor provider configurations.
* MFA providers (except phone) indicate whether they're enabled through this field. */
providerConfigs?: MultiFactorProviderConfig[];
}

/**
* Interface representing a multi-factor auth provider configuration.
* This interface is used for second factor auth providers other than SMS.
* Interface representing a multi-factor auth provider configuration.
* This interface is used for second factor auth providers other than SMS.
* Currently, only TOTP is supported.
*/export interface MultiFactorProviderConfig {
/**
Expand All @@ -528,7 +528,7 @@ export interface MultiFactorConfig {
}

/**
* Interface representing configuration settings for TOTP second factor auth.
* Interface representing configuration settings for TOTP second factor auth.
*/
export interface TotpMultiFactorProviderConfig {
/**
Expand All @@ -540,7 +540,7 @@ export interface TotpMultiFactorProviderConfig {
/**
* Defines the multi-factor config class used to convert client side MultiFactorConfig
* to a format that is understood by the Auth server.
*
*
* @internal
*/
export class MultiFactorAuthConfig implements MultiFactorConfig {
Expand All @@ -555,7 +555,7 @@ export class MultiFactorAuthConfig implements MultiFactorConfig {
*/
public readonly factorIds: AuthFactorType[];
/**
* A list of multi-factor provider specific config.
* A list of multi-factor provider specific config.
* New MFA providers (except phone) will indicate enablement/disablement through this field.
*/
public readonly providerConfigs: MultiFactorProviderConfig[];
Expand Down Expand Up @@ -1947,8 +1947,8 @@ export class RecaptchaAuthConfig implements RecaptchaConfig {
}
}

/**
* A password policy configuration for a project or tenant
/**
* A password policy configuration for a project or tenant
*/
export interface PasswordPolicyConfig {
/**
Expand Down Expand Up @@ -2003,7 +2003,7 @@ export interface CustomStrengthOptionsConfig {
/**
* Defines the password policy config class used to convert client side PasswordPolicyConfig
* to a format that is understood by the Auth server.
*
*
* @internal
*/
export class PasswordPolicyAuthConfig implements PasswordPolicyConfig {
Expand Down Expand Up @@ -2110,7 +2110,7 @@ export class PasswordPolicyAuthConfig implements PasswordPolicyConfig {
'"PasswordPolicyConfig.enforcementState" must be either "ENFORCE" or "OFF".',
);
}

if (typeof options.forceUpgradeOnSignin !== 'undefined') {
if (!validator.isBoolean(options.forceUpgradeOnSignin)) {
throw new FirebaseAuthError(
Expand Down Expand Up @@ -2254,7 +2254,7 @@ export class PasswordPolicyAuthConfig implements PasswordPolicyConfig {
}
}

/**
/**
* Server side password policy configuration.
*/
export interface PasswordPolicyAuthServerConfig {
Expand All @@ -2264,14 +2264,14 @@ export interface PasswordPolicyAuthServerConfig {
}

/**
* Server side password policy versions configuration.
* Server side password policy versions configuration.
*/
export interface PasswordPolicyVersionsAuthServerConfig {
customStrengthOptions?: CustomStrengthOptionsAuthServerConfig;
}

/**
* Server side password policy constraints configuration.
* Server side password policy constraints configuration.
*/
export interface CustomStrengthOptionsAuthServerConfig {
containsLowercaseCharacter?: boolean;
Expand All @@ -2281,3 +2281,50 @@ export interface CustomStrengthOptionsAuthServerConfig {
minPasswordLength?: number;
maxPasswordLength?: number;
}

/**
* The configuration for the email privacy on the project or tenant.
*/
export interface EmailPrivacyConfig {
/**
* Variable indiciating email privacy enabled of not.
*/
enableImprovedEmailPrivacy?: boolean;
}

/**
* Defines the EmailPrivacyAuthConfig class used for validation.
*
* @internal
*/
export class EmailPrivacyAuthConfig {
public static validate(options: EmailPrivacyConfig): void {
if (!validator.isNonNullObject(options)) {
throw new FirebaseAuthError(
AuthClientErrorCode.INVALID_CONFIG,
'"EmailPrivacyConfig" must be a non-null object.',
);
}

const validKeys = {
enableImprovedEmailPrivacy: true,
};

for (const key in options) {
if (!(key in validKeys)) {
throw new FirebaseAuthError(
AuthClientErrorCode.INVALID_CONFIG,
`"${key}" is not a valid "EmailPrivacyConfig" parameter.`,
);
}
}

if (typeof options.enableImprovedEmailPrivacy !== 'undefined'
&& !validator.isBoolean(options.enableImprovedEmailPrivacy)) {
throw new FirebaseAuthError(
AuthClientErrorCode.INVALID_CONFIG,
'"EmailPrivacyConfig.enableImprovedEmailPrivacy" must be a valid boolean value.',
);
}
}
}
48 changes: 37 additions & 11 deletions src/auth/project-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import {
PasswordPolicyAuthConfig,
PasswordPolicyAuthServerConfig,
PasswordPolicyConfig,
EmailPrivacyConfig,
EmailPrivacyAuthConfig,
} from './auth-config';
import { deepCopy } from '../utils/deep-copy';

Expand Down Expand Up @@ -53,6 +55,10 @@ export interface UpdateProjectConfigRequest {
* The password policy configuration to update on the project
*/
passwordPolicyConfig?: PasswordPolicyConfig;
/**
* The email privacy configuration to update on the project
*/
emailPrivacyConfig?: EmailPrivacyConfig;
}

/**
Expand All @@ -63,6 +69,7 @@ export interface ProjectConfigServerResponse {
mfa?: MultiFactorAuthServerConfig;
recaptchaConfig?: RecaptchaConfig;
passwordPolicyConfig?: PasswordPolicyAuthServerConfig;
emailPrivacyConfig?: EmailPrivacyConfig;
}

/**
Expand All @@ -73,6 +80,7 @@ export interface ProjectConfigClientRequest {
mfa?: MultiFactorAuthServerConfig;
recaptchaConfig?: RecaptchaConfig;
passwordPolicyConfig?: PasswordPolicyAuthServerConfig;
emailPrivacyConfig?: EmailPrivacyConfig;
}

/**
Expand All @@ -89,27 +97,29 @@ export class ProjectConfig {
/**
* The project's multi-factor auth configuration.
* Supports only phone and TOTP.
*/
*/
private readonly multiFactorConfig_?: MultiFactorConfig;

/**
* The multi-factor auth configuration.
*/
get multiFactorConfig(): MultiFactorConfig | undefined {
return this.multiFactorConfig_;
}
/**
* The reCAPTCHA configuration to update on the project.
* By enabling reCAPTCHA Enterprise integration, you are
* agreeing to the reCAPTCHA Enterprise
* {@link https://cloud.google.com/terms/service-terms | Term of Service}.
*/
private readonly recaptchaConfig_?: RecaptchaAuthConfig;

/**
* The multi-factor auth configuration.
*/
get multiFactorConfig(): MultiFactorConfig | undefined {
return this.multiFactorConfig_;
}
/**
* The password policy configuration for the project
*/
public readonly passwordPolicyConfig?: PasswordPolicyConfig;
/**
* The email privacy configuration for the project
*/
public readonly emailPrivacyConfig?: EmailPrivacyConfig;

/**
* Validates a project config options object. Throws an error on failure.
Expand All @@ -128,6 +138,7 @@ export class ProjectConfig {
multiFactorConfig: true,
recaptchaConfig: true,
passwordPolicyConfig: true,
emailPrivacyConfig: true,
}
// Check for unsupported top level attributes.
for (const key in request) {
Expand Down Expand Up @@ -156,6 +167,11 @@ export class ProjectConfig {
if (typeof request.passwordPolicyConfig !== 'undefined') {
PasswordPolicyAuthConfig.validate(request.passwordPolicyConfig);
}

// Validate Email Privacy Config if provided.
if (typeof request.emailPrivacyConfig !== 'undefined') {
EmailPrivacyAuthConfig.validate(request.emailPrivacyConfig);
}
}

/**
Expand All @@ -180,9 +196,12 @@ export class ProjectConfig {
if (typeof configOptions.passwordPolicyConfig !== 'undefined') {
request.passwordPolicyConfig = PasswordPolicyAuthConfig.buildServerRequest(configOptions.passwordPolicyConfig);
}
if (typeof configOptions.emailPrivacyConfig !== 'undefined') {
request.emailPrivacyConfig = configOptions.emailPrivacyConfig;
}
return request;
}

/**
* The reCAPTCHA configuration.
*/
Expand All @@ -200,7 +219,7 @@ export class ProjectConfig {
if (typeof response.smsRegionConfig !== 'undefined') {
this.smsRegionConfig = response.smsRegionConfig;
}
//Backend API returns "mfa" in case of project config and "mfaConfig" in case of tenant config.
//Backend API returns "mfa" in case of project config and "mfaConfig" in case of tenant config.
//The SDK exposes it as multiFactorConfig always.
if (typeof response.mfa !== 'undefined') {
this.multiFactorConfig_ = new MultiFactorAuthConfig(response.mfa);
Expand All @@ -211,6 +230,9 @@ export class ProjectConfig {
if (typeof response.passwordPolicyConfig !== 'undefined') {
this.passwordPolicyConfig = new PasswordPolicyAuthConfig(response.passwordPolicyConfig);
}
if (typeof response.emailPrivacyConfig !== 'undefined') {
this.emailPrivacyConfig = response.emailPrivacyConfig;
}
}
/**
* Returns a JSON-serializable representation of this object.
Expand All @@ -224,6 +246,7 @@ export class ProjectConfig {
multiFactorConfig: deepCopy(this.multiFactorConfig),
recaptchaConfig: this.recaptchaConfig_?.toJSON(),
passwordPolicyConfig: deepCopy(this.passwordPolicyConfig),
emailPrivacyConfig: deepCopy(this.emailPrivacyConfig),
};
if (typeof json.smsRegionConfig === 'undefined') {
delete json.smsRegionConfig;
Expand All @@ -237,6 +260,9 @@ export class ProjectConfig {
if (typeof json.passwordPolicyConfig === 'undefined') {
delete json.passwordPolicyConfig;
}
if (typeof json.emailPrivacyConfig === 'undefined') {
delete json.emailPrivacyConfig;
}
return json;
}
}
Expand Down
Loading