Skip to main content

Overview

The Two-Factor Authentication API provides comprehensive support for multiple 2FA providers including authenticator apps (TOTP), email, Duo, YubiKey, WebAuthn (FIDO2), and recovery codes. It manages both user-level and organization-level 2FA configurations.

TwoFactorService

Core service for managing two-factor authentication providers and state.

Methods

init()

Initializes the client-side TwoFactorProviders constant with localized translations. Must be called during application startup.

getSupportedProviders()

Gets a list of two-factor providers that are supported on the current client. For example, WebAuthn and Duo are not available on all clients. Parameters:
  • win - Window object for client capability detection
Returns: Promise<TwoFactorProviderDetails[]> - List of supported providers or empty list if none are stored

getDefaultProvider()

Gets the previously selected two-factor provider or the default provider based on priority. Parameters:
  • webAuthnSupported - Whether WebAuthn is supported by the client. Prevents WebAuthn from being the default provider if false
Returns: Promise<TwoFactorProviderType> - The default or selected provider type

setSelectedProvider()

Sets the selected two-factor provider in state. Parameters:
  • type - The type of two-factor provider to set as selected
Returns: Promise<void>

clearSelectedProvider()

Clears the selected two-factor provider from state. Returns: Promise<void>

setProviders()

Sets the list of available two-factor providers in state from the Identity service response. Parameters:
  • response - The response from Identity when 2FA is required. Includes the list of available 2FA providers
Returns: Promise<void>

clearProviders()

Clears the list of available two-factor providers from state. Returns: Promise<void>

getProviders()

Gets the list of two-factor providers from state. No filtering is done, so this returns all providers including potentially unsupported ones. Returns: Promise<Map<TwoFactorProviderType, object> | null> - Map of providers or null

Provider Configuration Methods (User)

getEnabledTwoFactorProviders()

Gets the enabled two-factor providers for the current user from the API. Used for settings management. Returns: Promise<ListResponse<TwoFactorProviderResponse>> - List of enabled provider configurations

getTwoFactorAuthenticator()

Gets the authenticator (TOTP) two-factor configuration for the current user. Requires user verification via master password or OTP. Parameters:
  • request - Secret verification request to prove authentication. Use UserVerificationService.buildRequest() to create
Returns: Promise<TwoFactorAuthenticatorResponse> - Authenticator configuration including the secret key

getTwoFactorEmail()

Gets the email two-factor configuration for the current user. Requires user verification. Parameters:
  • request - Secret verification request to prove authentication
Returns: Promise<TwoFactorEmailResponse> - Email two-factor configuration

getTwoFactorDuo()

Gets the Duo two-factor configuration for the current user. Requires user verification and active premium subscription. Parameters:
  • request - Secret verification request to prove authentication
Returns: Promise<TwoFactorDuoResponse> - Duo configuration

getTwoFactorYubiKey()

Gets the YubiKey OTP two-factor configuration for the current user. Requires user verification and active premium subscription. Parameters:
  • request - Secret verification request to prove authentication
Returns: Promise<TwoFactorYubiKeyResponse> - YubiKey configuration

getTwoFactorWebAuthn()

Gets the WebAuthn (FIDO2) two-factor configuration for the current user. Requires user verification. Parameters:
  • request - Secret verification request to prove authentication
Returns: Promise<TwoFactorWebAuthnResponse> - WebAuthn configuration including registered credentials

getTwoFactorWebAuthnChallenge()

Gets a WebAuthn challenge for registering a new WebAuthn credential. Must be called before putTwoFactorWebAuthn() to obtain the cryptographic challenge required for credential creation. Parameters:
  • request - Secret verification request to prove authentication
Returns: Promise<ChallengeResponse> - Credential creation options containing the challenge

getTwoFactorRecover()

Gets the recovery code configuration for the current user. The recovery code should be stored securely by the user. Requires user verification. Parameters:
  • request - Secret verification request to prove authentication
Returns: Promise<TwoFactorRecoverResponse> - Recovery code configuration

Provider Update Methods (User)

putTwoFactorAuthenticator()

Enables or updates the authenticator (TOTP) two-factor provider. Validates the provided token against the shared secret before enabling. Parameters:
  • request - Update request containing the configuration. Use UserVerificationService.buildRequest() to create
Returns: Promise<TwoFactorAuthenticatorResponse> - Updated authenticator configuration

deleteTwoFactorAuthenticator()

Disables the authenticator (TOTP) two-factor provider for the current user. Requires user verification token. Parameters:
  • request - Disable request. Use UserVerificationService.buildRequest() to create
Returns: Promise<TwoFactorProviderResponse> - Updated provider status

putTwoFactorEmail()

Enables or updates the email two-factor provider. Validates the email verification token sent via postTwoFactorEmailSetup() before enabling. Parameters:
  • request - Update request. Use UserVerificationService.buildRequest() to create
Returns: Promise<TwoFactorEmailResponse> - Updated email two-factor configuration

putTwoFactorDuo()

Enables or updates the Duo two-factor provider for the current user. Requires user verification and active premium subscription. Parameters:
  • request - Update request. Use UserVerificationService.buildRequest() to create
Returns: Promise<TwoFactorDuoResponse> - Updated Duo configuration

putTwoFactorYubiKey()

Enables or updates the YubiKey OTP two-factor provider. Validates each provided YubiKey by testing an OTP from the device. Supports up to 5 YubiKey devices. Requires user verification and active premium subscription. Parameters:
  • request - Update request. Use UserVerificationService.buildRequest() to create
Returns: Promise<TwoFactorYubiKeyResponse> - Updated YubiKey configuration

putTwoFactorWebAuthn()

Registers a new WebAuthn (FIDO2) credential for two-factor authentication. Must be called after getTwoFactorWebAuthnChallenge() to complete the registration flow. Parameters:
  • request - Update request containing the device response. Use UserVerificationService.buildRequest() to create
Returns: Promise<TwoFactorWebAuthnResponse> - Updated WebAuthn configuration with the new credential

deleteTwoFactorWebAuthn()

Removes a specific WebAuthn (FIDO2) credential from the user’s account. Other registered WebAuthn credentials remain active. Requires user verification. Parameters:
  • request - Delete request. Use UserVerificationService.buildRequest() to create
Returns: Promise<TwoFactorWebAuthnResponse> - Updated WebAuthn configuration

putTwoFactorDisable()

Disables a specific two-factor provider for the current user. The provider will no longer be required or usable. Requires user verification. Parameters:
  • request - Provider request. Use UserVerificationService.buildRequest() to create
Returns: Promise<TwoFactorProviderResponse> - Updated provider status

Email 2FA Methods

postTwoFactorEmailSetup()

Initiates email two-factor setup by sending a verification code to the specified email address. This is the first step in enabling email two-factor authentication. The verification code must be provided to putTwoFactorEmail() to complete setup. Only used during initial configuration, not during login flows. Parameters:
  • request - Email request. Use UserVerificationService.buildRequest() to create
Returns: Promise<any> - Resolves when verification email has been sent

postTwoFactorEmail()

Sends a two-factor authentication code via email during the login flow. Supports multiple authentication contexts including standard login, SSO, and passwordless flows. This is used to deliver codes during authentication, not during initial setup. Parameters:
  • request - Email request. Use UserVerificationService.buildRequest() to create
Returns: Promise<any> - Resolves when authentication email has been sent

Organization Methods

getTwoFactorOrganizationProviders()

Gets the enabled two-factor providers for an organization. Requires organization administrator permissions. Parameters:
  • organizationId - The ID of the organization
Returns: Promise<ListResponse<TwoFactorProviderResponse>> - List of enabled provider configurations

getTwoFactorOrganizationDuo()

Gets the Duo two-factor configuration for an organization. Requires user verification and organization policy management permissions. Parameters:
  • organizationId - The ID of the organization
  • request - Secret verification request
Returns: Promise<TwoFactorDuoResponse> - Organization Duo configuration

putTwoFactorOrganizationDuo()

Enables or updates the Duo two-factor provider for an organization. Requires user verification and organization policy management permissions. Parameters:
  • organizationId - The ID of the organization
  • request - Update request
Returns: Promise<TwoFactorDuoResponse> - Updated organization Duo configuration

putTwoFactorOrganizationDisable()

Disables a specific two-factor provider for an organization. Requires user verification and organization policy management permissions. Parameters:
  • organizationId - The ID of the organization
  • request - Provider request
Returns: Promise<TwoFactorProviderResponse> - Updated provider status

Types and Enums

TwoFactorProviderType

TwoFactorProviderDetails

TokenTwoFactorRequest


Example Usage

Handling 2FA During Login

Enabling Authenticator 2FA

Setting Up Email 2FA

Registering WebAuthn Security Key

Disabling a Provider

Organization Duo Setup