mirror of
https://github.com/bitwarden/browser
synced 2025-12-11 22:03:36 +00:00
Add the ability for custom validation logic to be injected into UserVerificationDialogComponent (#8770)
* Introduce `verificationType` * Update template to use `verificationType` * Implement a path for `verificationType = 'custom'` * Delete `clientSideOnlyVerification` * Update `EnrollMasterPasswordResetComponent` to include a server-side hash check * Better describe the custom scenerio through comments * Add an example of the custom verficiation scenerio * Move execution of verification function into try/catch * Migrate existing uses of `clientSideOnlyVerification` * Use generic type option instead of casting * Change "given" to "determined" in a comment
This commit is contained in:
@@ -142,6 +142,31 @@ export class UserVerificationDialogComponent {
|
||||
* return;
|
||||
* }
|
||||
*
|
||||
* ----------------------------------------------------------
|
||||
*
|
||||
* @example
|
||||
* // Example 4: Custom user verification validation
|
||||
*
|
||||
* const result = await UserVerificationDialogComponent.open(dialogService, {
|
||||
* verificationType: {
|
||||
* type: "custom",
|
||||
* // Pass in a function that will be used to validate the input of the
|
||||
* // verification dialog, returning true when finished.
|
||||
* verificationFn: async (secret: VerificationWithSecret) => {
|
||||
* const request = await userVerificationService.buildRequest<CustomRequestType>(secret);
|
||||
*
|
||||
* // ... Do something with the custom request type
|
||||
*
|
||||
* await someServicer.sendMyRequestThatVerfiesUserIdentity(
|
||||
* // ... Some other data
|
||||
* request,
|
||||
* );
|
||||
* return true;
|
||||
* },
|
||||
* },
|
||||
* });
|
||||
*
|
||||
* // ... Evaluate the result as usual
|
||||
*/
|
||||
static async open(
|
||||
dialogService: DialogService,
|
||||
@@ -202,6 +227,18 @@ export class UserVerificationDialogComponent {
|
||||
}
|
||||
|
||||
try {
|
||||
if (
|
||||
typeof this.dialogOptions.verificationType === "object" &&
|
||||
this.dialogOptions.verificationType.type === "custom"
|
||||
) {
|
||||
const success = await this.dialogOptions.verificationType.verificationFn(this.secret.value);
|
||||
this.close({
|
||||
userAction: "confirm",
|
||||
verificationSuccess: success,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: once we migrate all user verification scenarios to use this new implementation,
|
||||
// we should consider refactoring the user verification service handling of the
|
||||
// OTP and MP flows to not throw errors on verification failure.
|
||||
|
||||
Reference in New Issue
Block a user