Interface for a two factor service.

interface TwoFactorServiceInterface {
    confirmRegisterTwoFactorMethodForUser: <
        Role extends string,
        UserType extends BaseUser<Role>,
        TwoFactorRequestRegisterData,
        TwoFactorConfirmRegisterData,
    >(
        user: UserType,
        method: TwoFactorMethod<
            TwoFactorRequestRegisterData,
            TwoFactorConfirmRegisterData,
        >,
        data: TwoFactorConfirmRegisterData,
    ) => Promise<void>;
    has2fa: (
        user: BaseUser<string>,
        request: HttpRequest | WebsocketRequest,
        allowedMethods?: TwoFactorMethods,
    ) => Promise<boolean>;
    init: (twoFactorMethods: TwoFactorMethods) => Promise<void>;
    requestRegisterTwoFactorMethodForUser: <
        Role extends string,
        UserType extends BaseUser<Role>,
        TwoFactorRequestRegisterData,
        TwoFactorConfirmRegisterData,
    >(
        user: UserType,
        method: TwoFactorMethod<
            TwoFactorRequestRegisterData,
            TwoFactorConfirmRegisterData,
        >,
        data: TwoFactorRequestRegisterData,
    ) => Promise<void>;
    twoFactorMethods: TwoFactorMethods;
    unregisterTwoFactorMethodForUser: <
        Role extends string,
        UserType extends BaseUser<Role>,
        TwoFactorRequestRegisterData,
        TwoFactorConfirmRegisterData,
    >(
        user: UserType,
        method: TwoFactorMethod<
            TwoFactorRequestRegisterData,
            TwoFactorConfirmRegisterData,
        >,
    ) => Promise<void>;
}

Implemented by

Properties

confirmRegisterTwoFactorMethodForUser: <
    Role extends string,
    UserType extends BaseUser<Role>,
    TwoFactorRequestRegisterData,
    TwoFactorConfirmRegisterData,
>(
    user: UserType,
    method: TwoFactorMethod<
        TwoFactorRequestRegisterData,
        TwoFactorConfirmRegisterData,
    >,
    data: TwoFactorConfirmRegisterData,
) => Promise<void>

Confirms the registration of the given two factor method for the given user.

has2fa: (
    user: BaseUser<string>,
    request: HttpRequest | WebsocketRequest,
    allowedMethods?: TwoFactorMethods,
) => Promise<boolean>

Checks if the incoming request has some second factor.

init: (twoFactorMethods: TwoFactorMethods) => Promise<void>

Initializes the service.

requestRegisterTwoFactorMethodForUser: <
    Role extends string,
    UserType extends BaseUser<Role>,
    TwoFactorRequestRegisterData,
    TwoFactorConfirmRegisterData,
>(
    user: UserType,
    method: TwoFactorMethod<
        TwoFactorRequestRegisterData,
        TwoFactorConfirmRegisterData,
    >,
    data: TwoFactorRequestRegisterData,
) => Promise<void>

Requests the registration of the given two factor method for the given user.

twoFactorMethods: TwoFactorMethods

The different two factor methods provided.

unregisterTwoFactorMethodForUser: <
    Role extends string,
    UserType extends BaseUser<Role>,
    TwoFactorRequestRegisterData,
    TwoFactorConfirmRegisterData,
>(
    user: UserType,
    method: TwoFactorMethod<
        TwoFactorRequestRegisterData,
        TwoFactorConfirmRegisterData,
    >,
) => Promise<void>

Removes the given two factor method from the given user.