Skip to content

Commit e0f5257

Browse files
committed
Define internal password policy typings
1 parent 3a7c4a3 commit e0f5257

File tree

2 files changed

+111
-27
lines changed

2 files changed

+111
-27
lines changed
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/**
2+
* @license
3+
* Copyright 2023 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import { PasswordPolicy, PasswordValidationStatus } from "./public_types";
19+
20+
/**
21+
* Custom strength options supported in the password policy.
22+
*/
23+
export interface PasswordPolicyCustomStrengthOptions {
24+
/**
25+
* Minimum password length.
26+
*/
27+
readonly minPasswordLength?: number;
28+
/**
29+
* Maximum password length.
30+
*/
31+
readonly maxPasswordLength?: number;
32+
/**
33+
* Whether the password should contain a lowercase letter.
34+
*/
35+
readonly containsLowercaseLetter?: boolean;
36+
/**
37+
* Whether the password should contain an uppercase letter.
38+
*/
39+
readonly containsUppercaseLetter?: boolean;
40+
/**
41+
* Whether the password should contain a numeric character.
42+
*/
43+
readonly containsNumericCharacter?: boolean;
44+
/**
45+
* Whether the password should contain a non-alphanumeric character.
46+
*/
47+
readonly containsNonAlphanumericCharacter?: boolean;
48+
}
49+
50+
/**
51+
* Internal typing of password policy that includes the schema version and methods for
52+
* validating that a password meets the policy. The developer does not need access to
53+
* these properties and methods, so they are excluded from the public typing.
54+
*
55+
* @internal
56+
*/
57+
export interface PasswordPolicyInternal extends PasswordPolicy {
58+
/**
59+
* Schema version of the password policy.
60+
*/
61+
readonly schemaVersion: number;
62+
/**
63+
* Validates the password against the policy.
64+
* @param password Password to validate.
65+
*/
66+
validatePassword(password: string): PasswordValidationStatus;
67+
}
68+
69+
/**
70+
* Internal typing of password validation status that is modifiable. This allows us to
71+
* construct the validation status before returning it
72+
*
73+
* @internal
74+
*/
75+
export interface PasswordValidationStatusInternal extends PasswordValidationStatus {
76+
/**
77+
* Whether the password meets all requirements.
78+
*/
79+
isValid: boolean;
80+
/**
81+
* Whether the password meets the minimum password length.
82+
*/
83+
meetsMinPasswordLength?: boolean;
84+
/**
85+
* Whether the password meets the maximum password length.
86+
*/
87+
meetsMaxPasswordLength?: boolean;
88+
/**
89+
* Whether the password contains a lowercase letter, if required.
90+
*/
91+
containsLowercaseLetter?: boolean;
92+
/**
93+
* Whether the password contains an uppercase letter, if required.
94+
*/
95+
containsUppercaseLetter?: boolean;
96+
/**
97+
* Whether the password contains a numeric character, if required.
98+
*/
99+
containsNumericCharacter?: boolean;
100+
/**
101+
* Whether the password contains a non-alphanumeric character, if required.
102+
*/
103+
containsNonAlphanumericCharacter?: boolean;
104+
/**
105+
* The policy used to validate the password.
106+
*/
107+
passwordPolicy: PasswordPolicy;
108+
}

packages/auth/src/model/public_types.ts

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {
3232
OperationType as OperationTypeMap,
3333
ActionCodeOperation as ActionCodeOperationMap
3434
} from './enum_maps';
35+
import { PasswordPolicyCustomStrengthOptions } from './password_policy';
3536

3637
export { CompleteFn, ErrorFn, NextFn, Unsubscribe };
3738

@@ -1262,36 +1263,11 @@ export interface PasswordPolicy {
12621263
/**
12631264
* Requirements enforced by this password policy.
12641265
*/
1265-
readonly customStrengthOptions: {
1266-
/**
1267-
* Minimum password length.
1268-
*/
1269-
readonly minPasswordLength?: number;
1270-
/**
1271-
* Maximum password length.
1272-
*/
1273-
readonly maxPasswordLength?: number;
1274-
/**
1275-
* Whether the password should contain a lowercase letter.
1276-
*/
1277-
readonly containsLowercaseLetter?: boolean;
1278-
/**
1279-
* Whether the password should contain an uppercase letter.
1280-
*/
1281-
readonly containsUppercaseLetter?: boolean;
1282-
/**
1283-
* Whether the password should contain a numeric character.
1284-
*/
1285-
readonly containsNumericCharacter?: boolean;
1286-
/**
1287-
* Whether the password should contain a non-alphanumeric character.
1288-
*/
1289-
readonly containsNonAlphanumericCharacter?: boolean;
1290-
};
1266+
readonly customStrengthOptions: PasswordPolicyCustomStrengthOptions;
12911267
/**
12921268
* List of characters that are considered non-alphanumeric during validation.
12931269
*/
1294-
readonly allowedNonAlphanumericCharacters: string[];
1270+
readonly allowedNonAlphanumericCharacters?: string[];
12951271
}
12961272

12971273
/**

0 commit comments

Comments
 (0)