You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/end-user-flows/account-settings/by-account-api.mdx
+154-2Lines changed: 154 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -51,7 +51,9 @@ Some frequent use cases are listed below:
51
51
To learn more about the available APIs, please visit [Logto Account API Reference](https://openapi.logto.io/group/endpoint-my-account) and [Logto Verification API Reference](https://openapi.logto.io/group/endpoint-verifications).
52
52
53
53
:::note
54
-
Dedicated Account APIs for the following settings are coming soon: MFA, SSO, Custom data (user), and Account deletion. In the meantime, you can implement these features using the Logto Management APIs. See [Account settings by Management API](/end-user-flows/account-settings/by-management-api) for more details.
54
+
Dedicated Account APIs for the following settings are coming soon: SSO, Custom data (user), and Account deletion. In the meantime, you can implement these features using the Logto Management APIs. See [Account settings by Management API](/end-user-flows/account-settings/by-management-api) for more details.
55
+
56
+
MFA management APIs (TOTP and backup codes) are currently under development and only available when the `isDevFeaturesEnabled` flag is set to `true`. WebAuthn passkey management is fully available.
55
57
:::
56
58
57
59
## How to enable Account API \{#how-to-enable-account-api}
@@ -256,7 +258,7 @@ curl -X POST https://[tenant-id].logto.app/api/verifications/verification-code/v
256
258
After verifying the code, you can now update the user's email, set the `verificationId` to the request body as `newIdentifierVerificationRecordId`.
Remember to [enable MFA and TOTP](/end-user-flows/mfa) first.
470
+
:::
471
+
472
+
:::note
473
+
To use this method, you need to enable the `mfa` field in the account center settings.
474
+
:::
475
+
476
+
**Step 1: Generate a TOTP secret.**
477
+
478
+
```bash
479
+
curl -X POST https://[tenant-id].logto.app/api/my-account/mfa-verifications/totp-secret/generate \
480
+
-H 'authorization: Bearer <access_token>' \
481
+
-H 'content-type: application/json'
482
+
```
483
+
484
+
The response body would be like:
485
+
486
+
```json
487
+
{
488
+
"secret": "..."
489
+
}
490
+
```
491
+
492
+
**Step 2: Display the TOTP secret to the user.**
493
+
494
+
Use the secret to generate a QR code or display it directly to the user. The user should add it to their authenticator app (such as Google Authenticator, Microsoft Authenticator, or Authy).
-`verification_record_id`: a valid verification record ID, granted by verifying the user's existing factor. You can refer to the [Get a verification record ID](#get-a-verification-record-id) section for more details.
521
+
-`type`: must be `Totp`.
522
+
-`secret`: the TOTP secret generated in step 1.
523
+
524
+
:::note
525
+
A user can only have one TOTP factor at a time. If the user already has a TOTP factor, attempting to add another one will result in a 422 error.
526
+
:::
527
+
528
+
### Manage backup codes \{#manage-backup-codes}
529
+
530
+
:::note
531
+
Remember to [enable MFA and backup codes](/end-user-flows/mfa) first.
532
+
:::
533
+
534
+
:::note
535
+
To use this method, you need to enable the `mfa` field in the account center settings.
536
+
:::
537
+
538
+
**Step 1: Generate new backup codes:**
539
+
540
+
```bash
541
+
curl -X POST https://[tenant-id].logto.app/api/my-account/mfa-verifications/backup-codes/generate \
542
+
-H 'authorization: Bearer <access_token>' \
543
+
-H 'content-type: application/json'
544
+
```
545
+
546
+
The response body would be like:
547
+
548
+
```json
549
+
{
550
+
"codes": ["...", "...", "..."]
551
+
}
552
+
```
553
+
554
+
**Step 2: Display backup codes to the user:**
555
+
556
+
:::important
557
+
Before binding the backup codes to the user's account, you must display them to the user and instruct them to:
558
+
559
+
- Download or write down these codes immediately
560
+
- Store them in a secure location
561
+
- Understand that each code can only be used once
562
+
- Know that these codes are their last resort if they lose access to their primary MFA methods
563
+
564
+
You should display the codes in a clear, easy-to-copy format and consider providing a download option (e.g., as a text file or PDF).
565
+
:::
566
+
567
+
**Step 3: Bind backup codes to the user account:**
568
+
569
+
```bash
570
+
curl -X POST https://[tenant-id].logto.app/api/my-account/mfa-verifications \
-`verification_record_id`: a valid verification record ID, granted by verifying the user's existing factor. You can refer to the [Get a verification record ID](#get-a-verification-record-id) section for more details.
578
+
-`type`: must be `BackupCode`.
579
+
-`codes`: the array of backup codes generated in the previous step.
580
+
581
+
:::note
582
+
583
+
- A user can only have one set of backup codes at a time. If all codes have been used, the user needs to generate and bind new codes.
584
+
- Backup codes cannot be the only MFA factor. The user must have at least one other MFA factor (such as WebAuthn or TOTP) enabled.
0 commit comments