diff --git a/docs/developers/actions/post-sign-in.mdx b/docs/developers/actions/post-sign-in.mdx index 2e14aa5e35c..b3601277a15 100644 --- a/docs/developers/actions/post-sign-in.mdx +++ b/docs/developers/actions/post-sign-in.mdx @@ -26,14 +26,14 @@ type PostSignInEvent = { `event.user` includes the standard [user profile](/user-management/user-data#user-profile), plus: -| Field | Description | -| ------------------------ | -------------------------------------------- | -| `hasPassword` | Whether the user has a local password | -| `ssoIdentities` | Enterprise SSO identities linked to the user | -| `mfaVerificationFactors` | MFA factor types configured for the user | -| `roles` | Global roles and their API resource scopes | -| `organizations` | Organizations the user belongs to | -| `organizationRoles` | Organization roles assigned to the user | +| Field | Description | +| ------------------------ | -------------------------------------------------------------------------------------------------------------------------------------- | +| `hasPassword` | Whether the user has a local password | +| `ssoIdentities` | Enterprise SSO identities linked to the user | +| `mfaVerificationFactors` | Explicitly stored MFA factor types configured for the user (`Totp`, `WebAuthn`, `BackupCode`); excludes implicit email/SMS MFA factors | +| `roles` | Global roles and their API resource scopes | +| `organizations` | Organizations the user belongs to | +| `organizationRoles` | Organization roles assigned to the user | The context also includes fields such as `applicationId`, `lastSignInAt`, `createdAt`, and `updatedAt`. It does not include plaintext passwords, password hashes, MFA secrets, or connector token-set secrets. diff --git a/docs/developers/audit-logs/event-types.mdx b/docs/developers/audit-logs/event-types.mdx index b23c9d7ff8c..fb33ffcf238 100644 --- a/docs/developers/audit-logs/event-types.mdx +++ b/docs/developers/audit-logs/event-types.mdx @@ -60,12 +60,15 @@ Feel free to [contact us](https://logto.io/contact) if you’d like to share you | Interaction.Register.Verification.Password.Submit | Create and verify identifier with password verification | | Interaction.Register.Verification.EmailVerificationCode.Create | Create and send register email verification code | | Interaction.Register.Verification.EmailVerificationCode.Submit | Verify register email verification code | +| Interaction.Register.Verification.PhoneVerificationCode.Create | Create and send register phone verification code | +| Interaction.Register.Verification.PhoneVerificationCode.Submit | Verify register phone verification code | | Interaction.Register.Verification.SmsVerificationCode.Create | Create and send register SMS verification code | | Interaction.Register.Verification.SmsVerificationCode.Submit | Verify register SMS verification code | | Interaction.Register.Verification.Social.Create | Create social authentication URL | | Interaction.Register.Verification.Social.Submit | Verify social authentication | | Interaction.Register.Verification.EnterpriseSso.Create | Create enterprise SSO authentication URL | | Interaction.Register.Verification.EnterpriseSso.Submit | Verify enterprise SSO authentication | +| Interaction.Register.SignInPasskey.Submit | Bind a sign-in passkey to the registering user | | Interaction.Register.Profile.Create | Put new register interaction profile | | Interaction.Register.Profile.Delete | Delete register interaction profile | | Interaction.Register.Profile.Update | Patch update register interaction profile | @@ -86,8 +89,13 @@ Feel free to [contact us](https://logto.io/contact) if you’d like to share you | Interaction.SignIn.Identifier.VerificationCode.Submit | Submit and verify sign-in identifier with verification code | | Interaction.SignIn.Verification.EmailVerificationCode.Create | Create and send sign-in email verification code | | Interaction.SignIn.Verification.EmailVerificationCode.Submit | Verify sign-in email verification code | +| Interaction.SignIn.Verification.PhoneVerificationCode.Create | Create and send sign-in phone verification code | +| Interaction.SignIn.Verification.PhoneVerificationCode.Submit | Verify sign-in phone verification code | | Interaction.SignIn.Verification.SmsVerificationCode.Create | Create and send sign-in SMS verification code | | Interaction.SignIn.Verification.SmsVerificationCode.Submit | Verify sign-in SMS verification code | +| Interaction.SignIn.Verification.SignInPasskey.Create | Create sign-in passkey authentication options | +| Interaction.SignIn.Verification.SignInPasskey.Submit | Verify sign-in passkey authentication | +| Interaction.SignIn.SignInPasskey.Submit | Bind a sign-in passkey to the signing-in user | | Interaction.SignIn.Identifier.Social.Create | Create social sign-in authorization-url | | Interaction.SignIn.Identifier.Social.Submit | Authenticate and submit social identifier | | Interaction.SignIn.Verification.Social.Create | Create social authentication URL | @@ -113,6 +121,8 @@ Feel free to [contact us](https://logto.io/contact) if you’d like to share you | Interaction.ForgotPassword.Identifier.VerificationCode.Submit | Submit and verify forgot-password verification code | | Interaction.ForgotPassword.Verification.EmailVerificationCode.Create | Create and send forgot-password email verification code | | Interaction.ForgotPassword.Verification.EmailVerificationCode.Submit | Verify forgot-password email verification code | +| Interaction.ForgotPassword.Verification.PhoneVerificationCode.Create | Create and send forgot-password phone verification code | +| Interaction.ForgotPassword.Verification.PhoneVerificationCode.Submit | Verify forgot-password phone verification code | | Interaction.ForgotPassword.Verification.SmsVerificationCode.Create | Create and send forgot-password SMS verification code | | Interaction.ForgotPassword.Verification.SmsVerificationCode.Submit | Verify forgot-password SMS verification code | | Interaction.ForgotPassword.Profile.Create | Put new forgot-password interaction profile | @@ -121,22 +131,44 @@ Feel free to [contact us](https://logto.io/contact) if you’d like to share you ## MFA \{#mfa} -| Key | Name | -| --------------------------------------------------- | ----------------------------------------------- | -| Interaction.Register.Verification.BackupCode.Create | Create backup codes for MFA binding | -| Interaction.Register.Verification.BackupCode.Submit | Verify backup code | -| Interaction.Register.Verification.Totp.Create | Create TOTP verification secret for MFA binding | -| Interaction.Register.Verification.Totp.Submit | Verify TOTP verification code | -| Interaction.Register.Verification.WebAuthn.Create | Create WebAuthn authentication | -| Interaction.Register.Verification.WebAuthn.Submit | Verify WebAuthn authentication | -| Interaction.SignIn.Verification.BackupCode.Create | Create backup codes for MFA binding | -| Interaction.SignIn.Verification.BackupCode.Submit | Verify backup code | -| Interaction.SignIn.Verification.Totp.Create | Create TOTP verification secret for MFA binding | -| Interaction.SignIn.Verification.Totp.Submit | Verify TOTP verification code | -| Interaction.SignIn.Verification.WebAuthn.Create | Create WebAuthn authentication | -| Interaction.SignIn.Verification.WebAuthn.Submit | Verify WebAuthn authentication | -| TrustedDevice.Created | Create a trusted-device credential | -| TrustedDevice.Used | Use a trusted device to fulfill sign-in MFA | +| Key | Name | +| ----------------------------------------------------------------- | -------------------------------------------------------- | +| Interaction.Register.BindMfa.BackupCode.Submit | Bind backup codes for MFA during registration | +| Interaction.Register.BindMfa.EmailVerificationCode.Submit | Bind email verification code for MFA during registration | +| Interaction.Register.BindMfa.PhoneVerificationCode.Submit | Bind phone verification code for MFA during registration | +| Interaction.Register.BindMfa.Totp.Submit | Bind TOTP for MFA during registration | +| Interaction.Register.BindMfa.WebAuthn.Submit | Bind WebAuthn passkey for MFA during registration | +| Interaction.Register.Verification.BackupCode.Create | Create backup codes for MFA binding | +| Interaction.Register.Verification.BackupCode.Submit | Verify backup code | +| Interaction.Register.Verification.MfaEmailVerificationCode.Create | Create and send register MFA email verification code | +| Interaction.Register.Verification.MfaEmailVerificationCode.Submit | Verify register MFA email verification code | +| Interaction.Register.Verification.MfaPhoneVerificationCode.Create | Create and send register MFA phone verification code | +| Interaction.Register.Verification.MfaPhoneVerificationCode.Submit | Verify register MFA phone verification code | +| Interaction.Register.Verification.Totp.Create | Create TOTP verification secret for MFA binding | +| Interaction.Register.Verification.Totp.Submit | Verify TOTP verification code | +| Interaction.Register.Verification.WebAuthn.Create | Create WebAuthn authentication | +| Interaction.Register.Verification.WebAuthn.Submit | Verify WebAuthn authentication | +| Interaction.SignIn.BindMfa.BackupCode.Submit | Bind backup codes for MFA during sign-in | +| Interaction.SignIn.BindMfa.EmailVerificationCode.Submit | Bind email verification code for MFA during sign-in | +| Interaction.SignIn.BindMfa.PhoneVerificationCode.Submit | Bind phone verification code for MFA during sign-in | +| Interaction.SignIn.BindMfa.Totp.Submit | Bind TOTP for MFA during sign-in | +| Interaction.SignIn.BindMfa.WebAuthn.Submit | Bind WebAuthn passkey for MFA during sign-in | +| Interaction.SignIn.Verification.BackupCode.Create | Create backup codes for MFA binding | +| Interaction.SignIn.Verification.BackupCode.Submit | Verify backup code | +| Interaction.SignIn.Verification.MfaEmailVerificationCode.Create | Create and send sign-in MFA email verification code | +| Interaction.SignIn.Verification.MfaEmailVerificationCode.Submit | Verify sign-in MFA email verification code | +| Interaction.SignIn.Verification.MfaPhoneVerificationCode.Create | Create and send sign-in MFA phone verification code | +| Interaction.SignIn.Verification.MfaPhoneVerificationCode.Submit | Verify sign-in MFA phone verification code | +| Interaction.SignIn.Verification.Totp.Create | Create TOTP verification secret for MFA binding | +| Interaction.SignIn.Verification.Totp.Submit | Verify TOTP verification code | +| Interaction.SignIn.Verification.WebAuthn.Create | Create WebAuthn authentication | +| Interaction.SignIn.Verification.WebAuthn.Submit | Verify WebAuthn authentication | +| TrustedDevice.Created | Create a trusted-device credential | +| TrustedDevice.Used | Use a trusted device to fulfill sign-in MFA | + +:::note +`MfaEmailVerificationCode` and `MfaPhoneVerificationCode` verification keys are defined in Logto's audit log schema (`LogKey`), while at runtime the Experience API MFA verification-code endpoints currently log `Interaction.{event}.Verification.EmailVerificationCode.{Create,Submit}` and `Interaction.{event}.Verification.PhoneVerificationCode.{Create,Submit}`. +::: ## SAML application \{#saml-application} diff --git a/docs/developers/custom-token-claims/create-script.mdx b/docs/developers/custom-token-claims/create-script.mdx index 7dec800c022..8eb33f6cc09 100644 --- a/docs/developers/custom-token-claims/create-script.mdx +++ b/docs/developers/custom-token-claims/create-script.mdx @@ -209,6 +209,65 @@ The context object contains the user data and grant data that relevant to the cu } ``` + ```ts + // VerificationType.SignInPasskey + { + id: string; + type: 'SignInPasskey'; + userId?: string; + verified: boolean; + registrationRpId?: string; + } + ``` + + ```ts + // VerificationType.MfaEmailVerificationCode + { + id: string; + type: 'MfaEmailVerificationCode'; + templateType: + | 'MfaVerification' + | 'BindMfa' + | 'SignIn' + | 'Register' + | 'ForgotPassword' + | 'OrganizationInvitation' + | 'Generic' + | 'UserPermissionValidation' + | 'BindNewIdentifier'; + verified: boolean; + userId?: string; + identifier: { + type: 'email'; + value: string; + }; + } + ``` + + ```ts + // VerificationType.MfaPhoneVerificationCode + { + id: string; + type: 'MfaPhoneVerificationCode'; + templateType: + | 'MfaVerification' + | 'BindMfa' + | 'SignIn' + | 'Register' + | 'ForgotPassword' + | 'OrganizationInvitation' + | 'Generic' + | 'UserPermissionValidation' + | 'BindNewIdentifier'; + verified: boolean; + userId?: string; + identifier: { + type: 'phone'; + value: string; + }; + } + ``` + ```ts // VerificationType.BackupCode (MFA) { diff --git a/docs/developers/webhooks/events.mdx b/docs/developers/webhooks/events.mdx index 6936b4680bd..04458dd7030 100644 --- a/docs/developers/webhooks/events.mdx +++ b/docs/developers/webhooks/events.mdx @@ -11,11 +11,12 @@ This guide list the different Logto webhook events and explains when each event ## User interaction webhook events \{#user-interaction-hook-events} -| Event type | Description | -| ----------------- | --------------------------------------------------------------------------- | -| PostRegister | A user successfully creates a new account via the UI interface. | -| PostSignIn | A user successfully signs in via the UI interface. | -| PostResetPassword | A user's password is successfully reset through the "Forgot password" flow. | +| Event type | Description | +| ------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------- | +| PostRegister | A user successfully creates a new account via the UI interface. | +| PostSignIn | A user successfully signs in via the UI interface. | +| PostSignInAdaptiveMfaTriggered | [Adaptive MFA](/end-user-flows/mfa/adaptive-mfa) triggers an MFA challenge during a sign-in flow (emitted before MFA verification finishes). | +| PostResetPassword | A user's password is successfully reset through the "Forgot password" flow. | ## Data mutation webhook events \{#data-mutation-hook-events} diff --git a/docs/developers/webhooks/request.mdx b/docs/developers/webhooks/request.mdx index b0509583849..25c586d44c7 100644 --- a/docs/developers/webhooks/request.mdx +++ b/docs/developers/webhooks/request.mdx @@ -23,11 +23,11 @@ Customizable headers can be overridden via the [secure webhook](/developers/webh The body is a JSON object. Its exact shape depends on which family the event belongs to: -| Family | Events | When it fires | -| ----------------- | -------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- | -| **User flow** | `PostRegister`, `PostSignIn`, `PostResetPassword` | A user completes a sign-up, sign-in, or password-reset flow handled by the Experience API. | -| **Data mutation** | `User.*`, `Role.*`, `Scope.*`, `Organization.*`, `OrganizationRole.*`, `OrganizationScope.*` | The underlying data model is mutated by a Management API call or a user flow on the Experience API. | -| **Exception** | `Identifier.Lockout`, `Message.RateLimited`, `Grant.LimitExceeded` | A security incident, for example an account locked after consecutive failed verification attempts. | +| Family | Events | When it fires | +| ----------------- | -------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| **User flow** | `PostRegister`, `PostSignIn`, `PostSignInAdaptiveMfaTriggered`, `PostResetPassword` | A user completes a sign-up, sign-in, or password-reset flow, or triggers [Adaptive MFA](/end-user-flows/mfa/adaptive-mfa) during sign-in on the Experience API. | +| **Data mutation** | `User.*`, `Role.*`, `Scope.*`, `Organization.*`, `OrganizationRole.*`, `OrganizationScope.*` | The underlying data model is mutated by a Management API call or a user flow on the Experience API. | +| **Exception** | `Identifier.Lockout`, `Message.RateLimited`, `Grant.LimitExceeded` | A security incident, for example an account locked after consecutive failed verification attempts. | Every family shares a small set of [common fields](#common-fields). Each family then layers on its own request-context fields plus an event-specific payload. @@ -55,19 +55,34 @@ The [test payload](/developers/webhooks/configure-webhooks#test-webhook) carries ## User flow event payloads \{#user-flow-event-payloads} -**Events:** `PostRegister`, `PostSignIn`, `PostResetPassword`. +**Events:** `PostRegister`, `PostSignIn`, `PostSignInAdaptiveMfaTriggered`, `PostResetPassword`. -Fired when a user completes a sign-up, sign-in, or password-reset flow handled by the Experience API. In addition to the [common fields](#common-fields), the body carries: +Fired when a user completes a sign-up, sign-in, or password-reset flow handled by the Experience API, or when [Adaptive MFA](/end-user-flows/mfa/adaptive-mfa) triggers an MFA challenge during sign-in (`PostSignInAdaptiveMfaTriggered`). In addition to the [common fields](#common-fields), the body carries: -| Field | Type | Optional | Notes | -| ---------------- | -------------------------------------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- | -| interactionEvent | `'SignIn' \| 'Register' \| 'ForgotPassword'` | | The user-flow event type. Maps to `PostSignIn` / `PostRegister` / `PostResetPassword` respectively. The field name retains historical "interaction" naming. | -| sessionId | `string` | ✅ | The Session ID (not Interaction ID) for this event, if applicable. | -| userIp | `string` | ✅ | The IP address of the triggering request. | -| userId | `string` | ✅ | The User ID associated with this event, if applicable. | -| user | `UserEntity` | ✅ | The user entity associated with this event, if applicable. | -| applicationId | `string` | ✅ | The Application ID associated with this event, if applicable. | -| application | `ApplicationEntity` | ✅ | The application entity associated with this event, if applicable. | +| Field | Type | Optional | Notes | +| ----------------- | -------------------------------------------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| interactionEvent | `'SignIn' \| 'Register' \| 'ForgotPassword'` | | The user-flow event type (`'SignIn'` for `PostSignIn` and `PostSignInAdaptiveMfaTriggered`; `'Register'` for `PostRegister`; `'ForgotPassword'` for `PostResetPassword`). | +| sessionId | `string` | ✅ | The Session ID (not Interaction ID) for this event, if applicable. | +| userIp | `string` | ✅ | The IP address of the triggering request. | +| userId | `string` | ✅ | The User ID associated with this event, if applicable. | +| user | `UserEntity` | ✅ | The user entity associated with this event, if applicable. | +| applicationId | `string` | ✅ | The Application ID associated with this event, if applicable. | +| application | `ApplicationEntity` | ✅ | The application entity associated with this event, if applicable. | +| adaptiveMfaResult | `AdaptiveMfaResult` | ✅ | Present only on live `PostSignInAdaptiveMfaTriggered` deliveries (omitted from Console test payloads). See [PostSignInAdaptiveMfaTriggered payload](#postsigninadaptivemfatriggered-payload). | + +#### PostSignInAdaptiveMfaTriggered payload \{#postsigninadaptivemfatriggered-payload} + +When [Adaptive MFA](/end-user-flows/mfa/adaptive-mfa) triggers an MFA challenge during sign-in, Logto dispatches `PostSignInAdaptiveMfaTriggered` once per sign-in flow—even before the user finishes MFA verification (`PostSignIn` still fires only after sign-in completes). The body includes `adaptiveMfaResult`: + +```tsx +type AdaptiveMfaResult = { + requiresMfa: boolean; + triggeredRules: Array<{ + rule: 'new_country' | 'geo_velocity' | 'long_inactivity' | 'untrusted_ip'; + details: Record; + }>; +}; +``` #### Entity shapes \{#user-flow-entity-shapes} diff --git a/docs/end-user-flows/account-settings/by-account-center-ui.mdx b/docs/end-user-flows/account-settings/by-account-center-ui.mdx index 4024d341cc1..7cc25af1aee 100644 --- a/docs/end-user-flows/account-settings/by-account-center-ui.mdx +++ b/docs/end-user-flows/account-settings/by-account-center-ui.mdx @@ -44,6 +44,7 @@ The prebuilt Account Center UI provides the following pages, all accessible unde | `/account/authenticator-app` | Set up TOTP authenticator app | | `/account/authenticator-app/replace` | Replace existing TOTP authenticator app | | `/account/backup-codes/generate` | Generate new backup codes | +| `/account/backup-codes/regenerate` | Regenerate backup codes | | `/account/backup-codes/manage` | View and manage backup codes | For example, if your tenant endpoint is `https://example.logto.app`, the email update page would be available at `https://example.logto.app/account/email`. diff --git a/docs/end-user-flows/account-settings/by-management-api.mdx b/docs/end-user-flows/account-settings/by-management-api.mdx index 75547f07883..a294486fe45 100644 --- a/docs/end-user-flows/account-settings/by-management-api.mdx +++ b/docs/end-user-flows/account-settings/by-management-api.mdx @@ -183,13 +183,26 @@ Personal access tokens provide a secure way for users to grant [access token](ht ### User MFA settings management \{#user-mfa-settings-management} -| method | path | description | -| ------ | ------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------- | -| GET | [/api/users/\{userId\}/mfa-verifications](https://openapi.logto.io/operation/operation-listusermfaverifications) | Get user MFA settings by user ID. | -| POST | [/api/users/\{userId\}/mfa-verifications](https://openapi.logto.io/operation/operation-createusermfaverification) | Setup a user MFA verification by user ID. | -| DELETE | [/api/users/\{userId\}/mfa-verifications/\{verificationId\}](https://openapi.logto.io/operation/operation-deleteusermfaverification) | Delete a user MFA verification by ID. | +| method | path | description | +| ------ | ------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------- | +| GET | [/api/users/\{userId\}/mfa-verifications](https://openapi.logto.io/operation/operation-listusermfaverifications) | Get user MFA verifications by user ID. | +| POST | [/api/users/\{userId\}/mfa-verifications](https://openapi.logto.io/operation/operation-createusermfaverification) | Setup a user MFA verification by user ID. | +| DELETE | [/api/users/\{userId\}/mfa-verifications/\{verificationId\}](https://openapi.logto.io/operation/operation-deleteusermfaverification) | Delete a user MFA verification by ID. | +| GET | [/api/users/\{userId\}/logto-configs](https://openapi.logto.io/operation/operation-listuserlogtoconfigs) | Get user Logto MFA configuration flags by user ID. | +| PATCH | [/api/users/\{userId\}/logto-configs](https://openapi.logto.io/operation/operation-updateuserlogtoconfigs) | Update user Logto MFA configuration flags (such as `mfa.required` and `mfa.skipped`). | -Add the `includeWebAuthnCredentials=true` query parameter to the GET endpoint to include the stored WebAuthn credentials, for example to [export passkeys](/end-user-flows/mfa/webauthn#export-passkeys) to another system on the same domain. +Add the `includeWebAuthnCredentials=true` query parameter to `GET /api/users/{userId}/mfa-verifications` to include the stored WebAuthn credentials, for example to [export passkeys](/end-user-flows/mfa/webauthn#export-passkeys) to another system on the same domain. + +Use `PATCH /api/users/{userId}/logto-configs` with `{ "mfa": { "required": true } }` to require MFA setup for an individual user (`mfa.required` cannot be modified by the user through the Account API). + +### User trusted devices management \{#user-trusted-devices-management} + +| method | path | description | +| ------ | --------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------- | +| GET | [/api/users/\{userId\}/trusted-devices](https://openapi.logto.io/operation/operation-listusertrusteddevices) | List active trusted devices for a user. | +| DELETE | [/api/users/\{userId\}/trusted-devices/\{trustedDeviceId\}](https://openapi.logto.io/operation/operation-deleteusertrusteddevice) | Remove a trusted device by ID for a user. | + +Removing a trusted device applies to future sign-ins only and does not revoke existing sessions. See [MFA trusted devices](/end-user-flows/mfa/trusted-devices) for details. ### User account deletion \{#user-account-deletion} diff --git a/docs/end-user-flows/mfa/README.mdx b/docs/end-user-flows/mfa/README.mdx index 5a817392320..c5e990fbd67 100644 --- a/docs/end-user-flows/mfa/README.mdx +++ b/docs/end-user-flows/mfa/README.mdx @@ -43,6 +43,8 @@ Logto simplifies the MFA activation process with a one-click toggle, removing th - [Email verification](/end-user-flows/mfa/email-mfa): Use email messages to send one-time codes (verification codes) for authentication. - [Backup codes](/end-user-flows/mfa/backup-codes): Generate one-time-use backup codes for emergency access. -**Related MFA capabilities**: +**MFA policies and sign-in controls**: +- [Configure MFA](/end-user-flows/mfa/configure-mfa): Set global, organization, and per-user MFA policies, factor suggestions, and sign-in flow rules. - [Trusted devices](/end-user-flows/mfa/trusted-devices): Let users skip repeated MFA prompts on a trusted browser with a time-limited, revocable credential. Users opt in on a separate **Trust this device** page at the end of an eligible sign-in or sign-up flow. +- [Adaptive MFA](/end-user-flows/mfa/adaptive-mfa): Prompt for MFA verification during sign-in only when built-in risk rules trigger. diff --git a/docs/end-user-flows/mfa/adaptive-mfa.mdx b/docs/end-user-flows/mfa/adaptive-mfa.mdx new file mode 100644 index 00000000000..ec3216651e6 --- /dev/null +++ b/docs/end-user-flows/mfa/adaptive-mfa.mdx @@ -0,0 +1,52 @@ +--- +sidebar_position: 8 +sidebar_label: Adaptive MFA +--- + +# Adaptive MFA + +Adaptive MFA evaluates sign-in risk on each sign-in flow and challenges the user for MFA verification only when a risk rule triggers. Low-risk sign-ins can complete without an MFA verification prompt, reducing friction while keeping high-risk sign-ins protected. + +## How Adaptive MFA works \{#how-adaptive-mfa-works} + +When **Adaptive MFA** is enabled in Console > Multi-factor authentication: + +- **MFA setup stays non-skippable**: Enabling Adaptive MFA requires at least one MFA factor and one of the two non-skippable **MFA set-up prompt** policies (`Ask users to set up MFA during registration (non-skippable)` or `Ask users to set up MFA on their next sign-in attempt after registration (non-skippable)`). Users who do not yet have any MFA factor configured must still set up MFA during sign-up or at their next sign-in. +- **Risk rules run on sign-in**: When a user signs in (`SignIn` interaction) with MFA factors available, Logto evaluates the built-in risk rules described below. +- **Verification runs only when triggered**: If at least one rule triggers, Logto requires MFA verification before completing sign-in and dispatches the [`PostSignInAdaptiveMfaTriggered`](/developers/webhooks/webhooks-events#user-interaction-hook-events) webhook event. If no rule triggers, sign-in completes without an MFA verification challenge. + +## Built-in risk rules \{#built-in-risk-rules} + +Adaptive MFA evaluates four built-in risk rules on `SignIn` interactions: + +| Rule | Trigger condition | +| ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | +| **New country** | The request includes an ISO country code, the user has signed in before with at least one recorded country in the past **180 days**, and the current country is not in that history. | +| **Geo velocity** | Both the current request and the user's previous sign-in have latitude/longitude coordinates, elapsed time is positive, and the calculated travel speed exceeds **900 km/h**. | +| **Long inactivity** | The user has signed in before and more than **30 days** have elapsed since their last sign-in. | +| **Untrusted IP** | Upstream risk signals report a bot score below **30** or a verified-bot flag (`true`). | + +:::note +Logto records a user's country and geographic coordinates during sign-in and registration when location headers are present so later sign-ins have baseline history. Before a user has a prior sign-in timestamp (`lastSignInAt`, such as users created via the Management API before signing in) or prior country/coordinate history, `New country` and `Geo velocity` do not trigger; completing registration sets `lastSignInAt` and records location history if location headers were present during sign-up. +::: + +## Edge headers prerequisite \{#edge-headers-prerequisite} + +The **New country**, **Geo velocity**, and **Untrusted IP** rules rely on HTTP headers injected by an edge proxy in front of Logto: + +- Default header names: `x-logto-cf-country`, `x-logto-cf-city`, `x-logto-cf-latitude`, `x-logto-cf-longitude`, `x-logto-cf-bot-score`, `x-logto-cf-bot-verified`. +- In self-hosted deployments, if your proxy or CDN uses different header names, configure custom header mappings via the `INJECTED_HEADER_MAPPING_JSON` environment variable. + +Without location and bot-risk headers on incoming requests, those three rules receive no input signals, and **only the Long inactivity rule** (more than 30 days since last sign-in) can trigger Adaptive MFA. + +## Interaction with other MFA settings \{#interaction-with-other-mfa-settings} + +- **Per-user and organization requirements**: When **Adaptive MFA** is selected in Console, the **MFA setup prompt for users after organization enables MFA** setting (`organizationRequiredMfaPolicy`) is hidden and not saved. During sign-in under Adaptive MFA, low-risk sign-ins that trigger no risk rule are **not** challenged for MFA verification—even for users with [per-user MFA setup required](/end-user-flows/mfa/configure-mfa) (`mfa.required`) or members of [organizations that require MFA](/organizations/organization-management#require-mfa-for-organization-members) (`isMfaRequired`). Organization token exchange still rejects members who have no MFA factor configured when `isMfaRequired` is enabled. +- **User MFA opt-out settings**: Adaptive MFA ignores `skipMfaOnSignIn` and `enabled: false` (read-only `required` returned by `GET /api/my-account/mfa-settings` is `true`). Users are still challenged whenever a risk rule triggers. +- **Trusted devices**: A valid [trusted device](/end-user-flows/mfa/trusted-devices) credential can still fulfill the MFA verification challenge when an Adaptive MFA risk rule triggers. +- **Passkey sign-in**: Signing in with [passkey sign-in](/end-user-flows/sign-up-and-sign-in/passkey-sign-in) satisfies the WebAuthn MFA requirement for that sign-in without an extra MFA prompt. +- **Binding new factors during sign-in**: Because adding a new MFA factor during a sign-in interaction requires verifying an existing factor first, low-risk Adaptive MFA sign-ins that do not prompt MFA cannot bind additional factors inline during sign-in. Users can add or manage MFA factors via Account Center or the [Account API](/end-user-flows/account-settings/by-account-api). + +## Webhook notifications \{#webhook-notifications} + +Subscribing to the `PostSignInAdaptiveMfaTriggered` webhook event notifies your service whenever Adaptive MFA triggers an MFA challenge for a sign-in (`requiresMfa: true`), including the list of `triggeredRules`. Unlike `PostSignIn`, which fires only after sign-in completes, `PostSignInAdaptiveMfaTriggered` fires once per sign-in flow at the point Adaptive MFA requires verification—even before the user finishes MFA. See [Webhook request](/developers/webhooks/webhooks-request) for payload details. diff --git a/docs/end-user-flows/mfa/backup-codes.mdx b/docs/end-user-flows/mfa/backup-codes.mdx index d644409f122..ac0944d44bb 100644 --- a/docs/end-user-flows/mfa/backup-codes.mdx +++ b/docs/end-user-flows/mfa/backup-codes.mdx @@ -29,6 +29,13 @@ For detailed implementation steps and API endpoints, see [Account settings by Ac Due to backup codes being a secondary MFA factor, they can only be set up after a primary MFA factor has been successfully configured. A group of 10 auto-generated backup codes will be displayed to the user, which they can download and copy securely. User must manually confirm the backup codes to complete the MFA setup process. +Logto also prompts the user during sign-in to generate and save a new set of backup codes if **Backup codes** are enabled and the user already has another active factor but no remaining unused backup codes—for example: + +- All previously generated backup codes have been used. +- You enabled **Backup codes** after the user had already enrolled their primary MFA factor. + +During an existing user's sign-in, this re-prompt occurs only after the user verifies an MFA challenge (or signs in with a passkey); sign-ins that bypass MFA verification (such as a trusted device, a low-risk [Adaptive MFA](/end-user-flows/mfa/adaptive-mfa) sign-in, or user-skipped **Optional MFA**) do not prompt to bind new backup codes mid-sign-in, and normal [Enterprise SSO](/end-user-flows/enterprise-sso) sign-ins skip MFA setup prompts unless MFA is explicitly requested via `acr_values`. + Backup codes set up flow ## Backup codes verification flow \{#backup-codes-verification-flow} diff --git a/docs/end-user-flows/mfa/configure-mfa.mdx b/docs/end-user-flows/mfa/configure-mfa.mdx index 13fd313addf..fc6b5f4955b 100644 --- a/docs/end-user-flows/mfa/configure-mfa.mdx +++ b/docs/end-user-flows/mfa/configure-mfa.mdx @@ -23,7 +23,7 @@ Follow these steps to enable MFAs in users' Logto sign-in flow: - [Backup codes](/end-user-flows/mfa/backup-codes): This serves as a backup option when users can't verify any of the primary factors mentioned above. Enabling this option reduces friction for users' access successfully. 3. Choose the **Require MFA** policy from the dropdown. This policy controls when users must complete MFA during sign-in: - **Optional MFA** (_Optional MFA: Let users choose to enable MFA for their own account security_): Let users decide whether to enable MFA for their own account security. Users can skip MFA setup during sign-in and set it up later through your self-service account settings page. [Learn more](/end-user-flows/account-settings/) about implementing a user account settings page. - - **Adaptive MFA** (_Adaptive MFA: Only ask for MFA when a sign-in seems risky (e.g., new country / long inactivity)_): Apply MFA only when a sign-in appears unusual, so low-risk sign-ins can stay smoother while suspicious sign-ins get extra verification. To make that decision, Logto evaluates high-level contextual signals such as the user's inactivity level, whether the current sign-in context is broadly consistent with recent travel-related sign-in patterns, the state of the network connection, and other session or environmental indicators. This mode depends on your existing MFA setup (at least one MFA factor must be enabled), applies to end-user sign-in flows, and does not rely on device fingerprinting or precise location tracking. + - **Adaptive MFA** (_Adaptive MFA: Only ask for MFA when a sign-in seems risky (e.g., new country / long inactivity)_): Apply MFA only when a sign-in appears unusual, so low-risk sign-ins can stay smoother while suspicious sign-ins get extra verification. To make that decision, Logto evaluates built-in contextual risk rules (new country, geo velocity, long inactivity, and untrusted IP signals). This mode depends on your existing MFA setup (at least one MFA factor must be enabled), applies to end-user sign-in flows, and does not rely on device fingerprinting. See [Adaptive MFA](/end-user-flows/mfa/adaptive-mfa) for rule thresholds, edge header prerequisites, and webhook details. - **Mandatory MFA** (_Mandatory MFA: Requires all users to complete MFA every time they sign in_): Require all users to complete MFA on every sign-in. Users who have not set up MFA must complete setup before they can continue. - When **Optional MFA** is selected, configure the **MFA set-up prompt** policy: - **Do not ask users to set up MFA**: Users will not be prompted to set up MFA during sign-in or registration. @@ -45,7 +45,29 @@ If you need to prompt a user again after they skipped MFA enrollment, reset thei For products with a multi-tenant architecture that support [Organizations](/organizations), in most cases you don't need to require MFA for all users. Instead, MFA can be enabled on a per-organization basis, allowing you to tailor the requirements based on each client's needs. To get started, refer to [Requiring MFA for organization members](/organizations/organization-management#require-mfa-for-organization-members). -When **Optional MFA** is selected in the **Require MFA** dropdown, Console displays the **MFA setup prompt for users after organization enables MFA** setting. Set it to **Ask users to set up MFA on next sign-in (non-skippable)** so members of any organization that requires MFA are prompted to complete MFA setup at their next sign-in and cannot skip it. (This setting is hidden in Console when **Adaptive MFA** or **Mandatory MFA** is selected.) +When **Optional MFA** is selected in the **Require MFA** dropdown, Console displays the **MFA setup prompt for users after organization enables MFA** setting. Set it to **Ask users to set up MFA on next sign-in (non-skippable)** so members of any organization that requires MFA are prompted to complete MFA setup at their next sign-in and cannot skip it. (This setting is hidden in Console and not saved when **Adaptive MFA** or **Mandatory MFA** is selected.) + +Under **Adaptive MFA**, low-risk sign-ins that trigger no risk rule are not challenged for MFA verification even for users who have per-user **Require MFA setup** enabled or belong to an organization with `isMfaRequired` enabled. + +### Suggest adding another MFA factor \{#suggest-adding-another-mfa-factor} + +In Console > Multi-factor authentication, the **Suggest adding another MFA factor** switch (enabled by default; controlled by `mfa.skipAdditionalBindingSuggestion` in the Sign-in Experience API) prompts a user to add another MFA factor during sign-up or sign-in when: + +- The user's only MFA factor is the email address, phone number, or passkey they sign in with, and +- At least one other MFA factor is enabled for the tenant. + +Users can skip this prompt. When a user skips the suggestion, Logto persists `mfa.additionalBindingSuggestionSkipped: true` on the user's `logtoConfig` so the suggestion does not reappear on future sign-ins. You can update or reset this flag via the [Account API](/end-user-flows/account-settings/by-account-api) (`PATCH /api/my-account/logto-configs` with `{ "mfa": { "additionalBindingSuggestionSkipped": false } }`; note that `GET /api/my-account/logto-configs` and `GET /api/users/{userId}/logto-configs` do not return this field). + +### Per-user MFA requirement \{#per-user-mfa-requirement} + +Administrators can require MFA setup for an individual user regardless of the tenant's **Optional MFA** prompt setting: + +- **In Console**: Open Console > User management, select the user, and enable **Require MFA setup** in the **Multi-factor authentication** section. +- **Via Management API**: Call `PATCH /api/users/{userId}/logto-configs` with `{ "mfa": { "required": true } }` (and read it with `GET /api/users/{userId}/logto-configs`). See [Account settings by Management API](/end-user-flows/account-settings/by-management-api#user-mfa-settings-management). + +End users cannot modify `mfa.required` through the Account API (`PATCH /api/my-account/logto-configs`); for self-service clients, it is exposed read-only as `required` on `GET /api/my-account/mfa-settings`. + +When per-user `mfa.required` is `true`, the user must set up at least one MFA factor before completing sign-in and cannot skip setup. Under **Optional MFA**, it also requires MFA verification on sign-in even if the user enabled `skipMfaOnSignIn` or set `enabled: false`. Under **Adaptive MFA**, low-risk sign-ins that trigger no risk rule are still not challenged for MFA verification. ## MFA user flow \{#mfa-user-flow} @@ -82,6 +104,15 @@ If the user signs in with [passkey sign-in](/end-user-flows/sign-up-and-sign-in/ MFA verification flow +### Sign-in binding rules and exemptions \{#sign-in-binding-rules-and-exemptions} + +Keep the following behavior in mind when designing MFA journeys: + +- **Backup code re-prompting**: When **Backup codes** are enabled and a user already has another active MFA factor, Logto prompts the user during sign-in to generate and save a new set of backup codes if all previously generated codes have been used or if **Backup codes** were enabled after the user initially enrolled. +- **Verified factor required to bind during sign-in**: During a `SignIn` interaction where the user already has MFA factors available, binding a new factor (including saving regenerated backup codes or following the "Suggest adding another MFA factor" prompt) requires completing an MFA verification challenge first (or signing in via passkey sign-in or enterprise SSO). Sign-ins that bypass MFA verification—such as a [trusted device](/end-user-flows/mfa/trusted-devices), a low-risk [Adaptive MFA](/end-user-flows/mfa/adaptive-mfa) sign-in that triggered no rule, or user-skipped **Optional MFA** (`skipMfaOnSignIn` / `enabled: false`)—cannot bind new MFA factors during that sign-in flow. Users in those sessions can add factors afterward via Account Center or the [Account API](/end-user-flows/account-settings/by-account-api). +- **Enterprise SSO exemption**: Signing in or registering through [Enterprise SSO](/end-user-flows/enterprise-sso) skips tenant MFA verification and MFA setup prompts during that interaction (unless MFA is explicitly requested by the client via `acr_values`, such as `urn:logto:acr:mfa`). +- **Forgot password exemption**: The [Forgot password](/end-user-flows/sign-up-and-sign-in/reset-password) flow skips MFA verification and MFA setup prompts. + ## MFA management \{#mfa-management} Beyond the initial setup during sign-in/sign-up, users can manage their MFA settings through a self-service account center. This provides flexibility for users to bind or unbind MFA factors based on their needs. diff --git a/docs/end-user-flows/mfa/email-mfa.mdx b/docs/end-user-flows/mfa/email-mfa.mdx index e0eaae20d1e..488d50a1281 100644 --- a/docs/end-user-flows/mfa/email-mfa.mdx +++ b/docs/end-user-flows/mfa/email-mfa.mdx @@ -47,6 +47,10 @@ Email verification is one of the most universally accessible MFA methods. It lev The MFA setup prompt can appear during user registration or after sign-in, depending on your configured [MFA policy](/end-user-flows/mfa/configure-mfa#global-mfa-configuration). +:::note +Email MFA currently uses implicit enrollment based on the user's primary email address: whenever **Email verification code** is enabled in Console MFA settings, any user who has a verified primary email (`primaryEmail`) automatically counts as having Email MFA available during sign-in evaluation without binding a separate MFA factor record. Because it is derived from `primaryEmail` rather than stored in `mfaVerifications`, implicit Email MFA does not appear in `GET /api/my-account/mfa-verifications`, `GET /api/users/{userId}/mfa-verifications`, or `user.mfaVerificationFactors` (Custom JWT claims and `PostSignIn` Actions). +::: + The email MFA setup flow is affected by the following factors: - **Number of MFA primary factors**: If there are multiple primary factors, the user must choose one to configure. Primary factors are MFA methods other than backup codes. diff --git a/docs/end-user-flows/mfa/sms-mfa.mdx b/docs/end-user-flows/mfa/sms-mfa.mdx index 53b85bd18fb..5a66a7b476e 100644 --- a/docs/end-user-flows/mfa/sms-mfa.mdx +++ b/docs/end-user-flows/mfa/sms-mfa.mdx @@ -45,6 +45,10 @@ SMS verification, also referred to as Phone Number verification, is one of the m The MFA setup prompt can appear during user registration or after sign-in, depending on your configured [MFA policy](/end-user-flows/mfa/configure-mfa#global-mfa-configuration). +:::note +SMS MFA currently uses implicit enrollment based on the user's primary phone number: whenever **SMS verification code** is enabled in Console MFA settings, any user who has a verified primary phone (`primaryPhone`) automatically counts as having SMS MFA available during sign-in evaluation without binding a separate MFA factor record. Because it is derived from `primaryPhone` rather than stored in `mfaVerifications`, implicit SMS MFA does not appear in `GET /api/my-account/mfa-verifications`, `GET /api/users/{userId}/mfa-verifications`, or `user.mfaVerificationFactors` (Custom JWT claims and `PostSignIn` Actions). +::: + The SMS MFA setup flow is affected by the following factors: - **Number of MFA primary factors**: If there are multiple primary factors, the user must choose one to configure. Primary factors are MFA methods other than backup codes. diff --git a/docs/organizations/organization-management.mdx b/docs/organizations/organization-management.mdx index e8661ce0273..45ca63191d2 100644 --- a/docs/organizations/organization-management.mdx +++ b/docs/organizations/organization-management.mdx @@ -32,7 +32,8 @@ Once enabled, members without MFA configured will not be able to exchange organi Please note that: -- This feature only checks if the user has MFA configured. It does not force users to use MFA when exchanging access tokens. +- This feature only checks if the user has MFA configured when exchanging organization tokens (`isMfaRequired`). Sign-in prompting is controlled by the tenant's MFA policy: under **Optional MFA**, set **MFA setup prompt for users after organization enables MFA** to **Ask users to set up MFA on next sign-in (non-skippable)**. When **Adaptive MFA** is enabled at the tenant level, Console hides that organization prompt setting and low-risk sign-ins that trigger no risk rule are not challenged for MFA verification even for members of MFA-required organizations. +- This feature does not force users to verify MFA when exchanging access tokens. - This feature does not limit what MFA methods users can use. ### Just-in-Time provisioning \{#just-in-time-provisioning} diff --git a/docs/user-management/manage-users.mdx b/docs/user-management/manage-users.mdx index b05218dcb60..e35c94406bc 100644 --- a/docs/user-management/manage-users.mdx +++ b/docs/user-management/manage-users.mdx @@ -43,7 +43,7 @@ To view the details of a user, simply click on the corresponding row in the user - **Phone number** ([primary_phone](/user-management/user-data#primary_phone)): Editable - **Username** ([username](/user-management/user-data#username)): Editable - **Password** ([has_password](/user-management/user-data#has_password)): You can regenerate a random password. Learn more about "[Reset user password](#reset-user-password)". - - **Multi-factor authentication** ([mfa_verification_factor](/user-management/user-data#mfa_verification_factors)): View all authentication factors (e.g., passkeys, authenticator apps, backup codes) this user has set up. Factors can be removed in the Console. + - **Multi-factor authentication** ([mfa_verification_factor](/user-management/user-data#mfa_verification_factors)): View all authentication factors (e.g., passkeys, authenticator apps, backup codes) this user has set up, remove stored factors, and toggle **Require MFA setup** (`mfa.required`) to require this individual user to set up at least one MFA factor before completing sign-in without skipping. See [Per-user MFA requirement](/end-user-flows/mfa/configure-mfa#per-user-mfa-requirement) and [Adaptive MFA](/end-user-flows/mfa/adaptive-mfa) for how this interacts with tenant policies. - **Passkeys**: When [passkey sign-in](/end-user-flows/sign-up-and-sign-in/passkey-sign-in) is enabled in the tenant, you can also view the user's sign-in passkeys on the user details page and remove them if needed. These passkeys are backed by the same WebAuthn credential model used by MFA. - **Personal access token**: Create, view, rename, and delete [personal access tokens](/user-management/personal-access-token). - **Connection**: diff --git a/docs/user-management/user-data.mdx b/docs/user-management/user-data.mdx index dfe26b5737a..e151d071ec5 100644 --- a/docs/user-management/user-data.mdx +++ b/docs/user-management/user-data.mdx @@ -185,7 +185,9 @@ Once a user is suspended the pre-granted refresh tokens will be revoked immediat ### mfa_verification_factors \{#mfa_verification_factors} -_mfa_verification_factors_ is an array that lists the [multi-factor authentication](/end-user-flows/mfa) (MFA) methods associated with the user’s account. The possible values include: _Totp_ (Authenticator app OTP), _WebAuthn_ (Passkey), and _BackupCode_. +_mfa_verification_factors_ is an array that lists the explicitly stored [multi-factor authentication](/end-user-flows/mfa) (MFA) methods associated with the user’s account. The possible values include: _Totp_ (Authenticator app OTP), _WebAuthn_ (Passkey), and _BackupCode_. + +Implicit [Email verification code](/end-user-flows/mfa/email-mfa) and [SMS verification code](/end-user-flows/mfa/sms-mfa) MFA factors backed by `primaryEmail` and `primaryPhone` are evaluated automatically at sign-in without creating records in `mfaVerifications`, so they are not included in `mfaVerificationFactors`. ```tsx mfaVerificationFactors: ("Totp" | "WebAuthn" | "BackupCode")[];