Supabase. Auth. MFA. Behaviour behaviour
(supabase_auth v1.0.1)
View Source
Behaviour for MFA operations with type definitions.
This module defines all type specifications for Multi-Factor Authentication operations including factors, challenges, verification responses, and authenticator assurance levels.
Factor Types
Three types of MFA factors are supported:
- TOTP (
:totp) - Time-based One-Time Password using authenticator apps - Phone (
:phone) - SMS or WhatsApp-based verification - WebAuthn (
:webauthn) - Hardware security keys and biometric authentication
Type Hierarchy
All factor types share common fields (id, friendly_name, status, timestamps) but have type-specific additional fields:
totp_factor/0includestotpfield with QR code, secret, and URIphone_factor/0includesphonefield with E.164 formatted numberwebauthn_factor/0has no additional type-specific fields
The factor/0 type is a union of all three specific factor types.
Summary
Types
@type aal_level() :: :aal1 | :aal2
@type challenge_response() :: %{ id: String.t(), type: factor_type(), expires_at: integer() }
@type enroll_response() :: totp_factor() | phone_factor() | webauthn_factor()
@type factor() :: totp_factor() | phone_factor() | webauthn_factor()
@type factor_base() :: %{ id: String.t(), friendly_name: String.t() | nil, factor_type: factor_type(), status: factor_status(), created_at: String.t(), updated_at: String.t(), last_challenged_at: String.t() | nil }
@type factor_status() :: :verified | :unverified
@type factor_type() :: :totp | :phone | :webauthn
@type factors_list() :: %{ all: [factor()], totp: [totp_factor()], phone: [phone_factor()], webauthn: [webauthn_factor()] }
Callbacks
@callback challenge(Supabase.Client.t(), Supabase.Auth.Session.t(), String.t(), map()) :: {:ok, challenge_response() | webauthn_challenge_response()} | {:error, term()}
@callback challenge_and_verify( Supabase.Client.t(), Supabase.Auth.Session.t(), String.t(), String.t() ) :: {:ok, Supabase.Auth.Session.t()} | {:error, term()}
@callback enroll(Supabase.Client.t(), Supabase.Auth.Session.t(), map()) :: {:ok, enroll_response()} | {:error, term()}
@callback get_authenticator_assurance_level( Supabase.Client.t(), Supabase.Auth.Session.t() ) :: {:ok, aal_response()} | {:error, term()}
@callback list_factors(Supabase.Client.t(), Supabase.Auth.Session.t()) :: {:ok, factors_list()} | {:error, term()}
@callback unenroll(Supabase.Client.t(), Supabase.Auth.Session.t(), String.t()) :: {:ok, %{id: String.t()}} | {:error, term()}
@callback verify( Supabase.Client.t(), Supabase.Auth.Session.t(), String.t(), String.t(), map() ) :: {:ok, Supabase.Auth.Session.t()} | {:error, term()}