Skip to content

Commit 8b28abd

Browse files
RanyCopilot
andauthored
refactor: update account api docs (#1218)
* refactor: update account api docs Update Account API and custom domain docs * chore: update Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * chore: update Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * chore: update user data structure Add Collect user profile and Account API information into "User data structure > Custom data" docs --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent a9b19bd commit 8b28abd

4 files changed

Lines changed: 89 additions & 55 deletions

File tree

docs/end-user-flows/account-settings/by-account-api.mdx

Lines changed: 65 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ curl https://[tenant-id].logto.app/api/my-account \
108108

109109
### Retrieve user account information \{#retrieve-user-account-information}
110110

111+
To get user data, you can use the [`GET /api/my-account`](https://openapi.logto.io/operation/operation-getprofile) endpoint.
112+
111113
```bash
112114
curl https://[tenant-id].logto.app/api/my-account \
113115
-H 'authorization: Bearer <access_token>'
@@ -128,9 +130,9 @@ The response fields may vary depending on the account center settings.
128130

129131
### Update basic account information \{#update-basic-account-information}
130132

131-
Basic account information includes the username, name, avatar, and profile.
133+
Basic account information includes the username, name, avatar, custom data, and other profile information.
132134

133-
To update username, name, and avatar, you can use the `PATCH /api/my-account` endpoint.
135+
To update **username, name, avatar, and customData** you can use the [`PATCH /api/my-account`](https://openapi.logto.io/operation/operation-updateprofile) endpoint.
134136

135137
```bash
136138
curl -X PATCH https://[tenant-id].logto.app/api/my-account \
@@ -139,7 +141,7 @@ curl -X PATCH https://[tenant-id].logto.app/api/my-account \
139141
--data-raw '{"username":"...","name":"...","avatar":"..."}'
140142
```
141143

142-
To update profile, you can use the `PATCH /api/my-account/profile` endpoint.
144+
To update other profile information, including **familyName, givenName, middleName, nickname, profile (profile page URL), website, gender, birthdate, zoneinfo, locale, and address**, you can use the [`PATCH /api/my-account/profile`](https://openapi.logto.io/operation/operation-updateotherprofile) endpoint.
143145

144146
```bash
145147
curl -X PATCH https://[tenant-id].logto.app/api/my-account/profile \
@@ -154,11 +156,9 @@ For security reasons, the Account API requires an additional layer of authorizat
154156

155157
### Get a verification record id \{#get-a-verification-record-id}
156158

157-
First, you need to get a verification record ID. This can be used to verify the user's identity when updating identifiers.
158-
159-
To get a verification record ID, you can verify the user's password or send a verification code to the user's email or phone.
159+
First, you need to get a **verification record ID** with a 10-minute expiration (TTL). This can be used to verify the user's identity before updating sensitive information. This means once a user successfully verifies their identity via password, email verification code, or SMS verification code, they have 10 minutes to update their authentication-related data, including identifiers, credentials, social account linking, and MFA.
160160

161-
To learn more about verifications, please refer to [Security verification by Account API](/end-user-flows/security-verification).
161+
To get a verification record ID, you can [verify the user's password](#verify-the-users-password) or [send a verification code to the user's email or phone](#verify-by-sending-a-verification-code-to-the-users-email-or-phone).
162162

163163
#### Verify the user's password \{#verify-the-users-password}
164164

@@ -213,13 +213,15 @@ curl -X POST https://[tenant-id].logto.app/api/verifications/verification-code/v
213213

214214
After verifying the code, you can now use the verification record ID to update the user's identifier.
215215

216+
To learn more about verifications, please refer to [Security verification by Account API](/end-user-flows/security-verification).
217+
216218
### Send request with verification record id \{#send-request-with-verification-record-id}
217219

218220
When sending a request to update the user's identifier, you need to include the verification record ID in the request header with the `logto-verification-id` field.
219221

220222
### Update user's password \{#update-users-password}
221223

222-
To update the user's password, you can use the `POST /api/my-account/password` endpoint.
224+
To update the user's password, you can use the [`POST /api/my-account/password`](https://openapi.logto.io/operation/operation-updatepassword) endpoint.
223225

224226
```bash
225227
curl -X POST https://[tenant-id].logto.app/api/my-account/password \
@@ -237,7 +239,7 @@ To use this method, you need to [configure the email connector](/connectors/emai
237239

238240
To update or link a new email, you should first prove the ownership of the email.
239241

240-
Call the `POST /api/verifications/verification-code` endpoint to request a verification code.
242+
Call the [`POST /api/verifications/verification-code`](https://openapi.logto.io/operation/operation-createverificationbyverificationcode) endpoint to request a verification code.
241243

242244
```bash
243245
curl -X POST https://[tenant-id].logto.app/api/verifications/verification-code \
@@ -255,7 +257,7 @@ curl -X POST https://[tenant-id].logto.app/api/verifications/verification-code/v
255257
--data-raw '{"identifier":{"type":"email","value":"..."},"verificationId":"...","code":"..."}'
256258
```
257259

258-
After verifying the code, you can now update the user's email, set the `verificationId` to the request body as `newIdentifierVerificationRecordId`.
260+
After verifying the code, you can now call [`PATCH /api/my-account/primary-email`](https://openapi.logto.io/operation/operation-updateprimaryemail) to update the user's email, set the `verificationId` to the request body as `newIdentifierVerificationRecordId`.
259261

260262
```bash
261263
curl -X POST https://[tenant-id].logto.app/api/my-account/primary-email \
@@ -267,7 +269,7 @@ curl -X POST https://[tenant-id].logto.app/api/my-account/primary-email \
267269

268270
### Remove the user's email \{#remove-the-users-email}
269271

270-
To remove the user's email, you can use the `DELETE /api/my-account/primary-email` endpoint.
272+
To remove the user's email, you can use the [`DELETE /api/my-account/primary-email`](https://openapi.logto.io/operation/operation-deleteprimaryemail) endpoint.
271273

272274
```bash
273275
curl -X DELETE https://[tenant-id].logto.app/api/my-account/primary-email \
@@ -281,11 +283,11 @@ curl -X DELETE https://[tenant-id].logto.app/api/my-account/primary-email \
281283
To use this method, you need to [configure the SMS connector](/connectors/sms-connectors/), and make sure the `BindNewIdentifier` template is configured.
282284
:::
283285

284-
Similar to updating email, you can use the `PATCH /api/my-account/primary-phone` endpoint to update or link a new phone. And use the `DELETE /api/my-account/primary-phone` endpoint to remove the user's phone.
286+
Similar to updating email, you can use the [`PATCH /api/my-account/primary-phone`](https://openapi.logto.io/operation/operation-updateprimaryphone) endpoint to update or link a new phone. And use the [`DELETE /api/my-account/primary-phone`](https://openapi.logto.io/operation/operation-deleteprimaryphone) endpoint to remove the user's phone.
285287

286288
### Link a new social connection \{#link-a-new-social-connection}
287289

288-
To link a new social connection, first you should request an authorization URL:
290+
To link a new social connection, first you should request an authorization URL with [`POST /api/verifications/social`](https://openapi.logto.io/operation/operation-createverificationbysocial).
289291

290292
```bash
291293
curl -X POST https://[tenant-id].logto.app/api/verifications/social \
@@ -300,7 +302,7 @@ curl -X POST https://[tenant-id].logto.app/api/verifications/social \
300302

301303
In the response, you will find a `verificationRecordId`, keep it for later use.
302304

303-
After the user authorizes the application, you will receive a callback at the `redirectUri` with the `state` parameter. Then you can use the `POST /api/verifications/social/verify` endpoint to verify the social connection.
305+
After the user authorizes the application, you will receive a callback at the `redirectUri` with the `state` parameter. Then you can use the [`POST /api/verifications/social/verify`](https://openapi.logto.io/operation/operation-verifyverificationbysocial) endpoint to verify the social connection.
304306

305307
```bash
306308
curl -X POST https://[tenant-id].logto.app/api/verifications/social/verify \
@@ -311,7 +313,7 @@ curl -X POST https://[tenant-id].logto.app/api/verifications/social/verify \
311313

312314
The `connectorData` is the data returned by the social connector after the user authorizes the application, you need to parse and get the query parameters from the `redirectUri` in your callback page, and wrap them as a JSON as the value of the `connectorData` field.
313315

314-
Finally, you can use the `POST /api/my-account/identities` endpoint to link the social connection.
316+
Finally, you can use the [`POST /api/my-account/identities`](https://openapi.logto.io/operation/operation-adduseridentities) endpoint to link the social connection.
315317

316318
```bash
317319
curl -X POST https://[tenant-id].logto.app/api/my-account/identities \
@@ -323,7 +325,7 @@ curl -X POST https://[tenant-id].logto.app/api/my-account/identities \
323325

324326
### Remove a social connection \{#remove-a-social-connection}
325327

326-
To remove a social connection, you can use the `DELETE /api/my-account/identities` endpoint.
328+
To remove a social connection, you can use the [`DELETE /api/my-account/identities`](https://openapi.logto.io/operation/operation-deleteidentity) endpoint.
327329

328330
```bash
329331
curl -X DELETE https://[tenant-id].logto.app/api/my-account/identities/[connector_target_id] \
@@ -338,27 +340,36 @@ Remember to [enable MFA and WebAuthn](/end-user-flows/mfa) first.
338340
:::
339341

340342
:::note
341-
To use this method, you need to enable the `mfa` field in the account center settings.
343+
To use this method, you need to enable the `mfa` field in the [account center settings](#how-to-enable-account-api).
342344
:::
343345

344-
**Step 0: Add your front-end app origin to the related origins.**
346+
**Step 1: Add your front-end app origin to the related origins**
345347

346-
A passkey in Browser is linked to a specific hostname (RP ID), and only the origin of the RP ID can be used to register or verify a passkey. However, your front-end app which is sending the request to the Account API is not the same as Logto's sign-in page, so you need to add your front-end app origin to the related origins list. This will allow your front-end app to register and verify a passkey under other RP IDs.
348+
WebAuthn passkeys are bound to a specific hostname called the **Relying Party ID (RP ID)**. Only applications hosted on the RP ID's origin can register or authenticate with those passkeys.
347349

348-
By default, Logto will set the RP ID to the tenant domain, for example, if your tenant domain is `https://example.logto.app`, the RP ID will be `example.logto.app`. If you are using a custom domain, the RP ID will be the custom domain, for example, if your custom domain is `https://auth.example.com`, the RP ID will be `auth.example.com`.
350+
Since your front-end application calls the Account API from a different domain than Logto's authentication pages, you need to configure **Related Origins** to allow cross-origin passkey operations.
349351

350-
Now, let's add your front-end app origin to the related origins, for example, if your front-end app origin is `https://account.example.com`:
352+
**How Logto determines the RP ID:**
353+
354+
- **Default setup**: If you only use Logto's default domain `https://[tenant-id].logto.app`, the RP ID is `[tenant-id].logto.app`
355+
- **Custom domain**: If you've configured a [custom domain](/logto-cloud/custom-domain) like `https://auth.example.com`, the RP ID becomes `auth.example.com`
356+
357+
**Configure Related Origins:**
358+
359+
Use the [`PATCH /api/account-center`](https://openapi.logto.io/operation/operation-updateaccountcentersettings) endpoint to add your front-end application's origin. For example, if your app's account center runs on `https://account.example.com`:
351360

352361
```bash
353-
curl -X PATCH https://[tenant-id].logto.app/api/webauthn-connectors \
362+
curl -X PATCH https://[tenant-id].logto.app/api/account-center \
354363
-H 'authorization: Bearer <access_token>' \
355364
-H 'content-type: application/json' \
356365
--data-raw '{"webauthnRelatedOrigins":["https://account.example.com"]}'
357366
```
358367

359368
To learn more about the related origins, please refer to [Related Origin Requests](https://passkeys.dev/docs/advanced/related-origins/) documentation.
360369

361-
**Step 1: request new registration options.**
370+
**Step 2: Request new registration options**
371+
372+
Use the [`POST /api/verifications/web-authn/registration`](https://openapi.logto.io/operation/operation-generatewebauthnregistrationoptions) endpoint to request registration for a new passkey. Logto allows each user account to register multiple passkeys.
362373

363374
```bash
364375
curl -X POST https://[tenant-id].logto.app/api/verifications/web-authn/registration \
@@ -376,7 +387,7 @@ You'll get a response like:
376387
}
377388
```
378389

379-
**Step 2: register the passkey in local browser.**
390+
**Step 3: Register the passkey in local browser**
380391

381392
Take [`@simplewebauthn/browser`](https://simplewebauthn.dev/) as an example, you can use the `startRegistration` function to register the passkey in local browser.
382393

@@ -390,7 +401,11 @@ const response = await startRegistration({
390401
// Save the response for later use
391402
```
392403

393-
**Step 3: verify the passkey.**
404+
**Step 4: Verify the passkey registration**
405+
406+
Use the [`POST /api/verifications/web-authn/registration/verify`](https://openapi.logto.io/operation/operation-verifywebauthnregistration) endpoint to verify the passkey registration.
407+
408+
This step verifies the cryptographic signature generated by the authenticator to ensure the passkey was legitimately created and hasn't been tampered with during transmission.
394409

395410
```bash
396411
curl -X POST https://[tenant-id].logto.app/api/verifications/web-authn/registration/verify \
@@ -402,7 +417,9 @@ curl -X POST https://[tenant-id].logto.app/api/verifications/web-authn/registrat
402417
- `payload`: The response from the local browser in step 2.
403418
- `verificationRecordId`: The verification record ID returned by the server in step 1.
404419

405-
**Step 4: finally, you can link the passkey.**
420+
**Step 5: Link the passkey**
421+
422+
Finally, you can link the passkey to the user's account using the [`POST /api/my-account/mfa-verifications`](https://openapi.logto.io/operation/operation-addmfaverification) endpoint.
406423

407424
```bash
408425
curl -X POST https://[tenant-id].logto.app/api/my-account/mfa-verifications \
@@ -416,9 +433,9 @@ curl -X POST https://[tenant-id].logto.app/api/my-account/mfa-verifications \
416433
- `type`: the type of the MFA factor, currently only `WebAuthn` is supported.
417434
- `newIdentifierVerificationRecordId`: the verification record ID returned by the server in step 1.
418435

419-
### Manage existing WebAuthn passkey \{#manage-existing-webauthn-passkey}
436+
### Manage existing WebAuthn passkeys \{#manage-existing-webauthn-passkeys}
420437

421-
To manage an existing WebAuthn passkey, you can use the `GET /api/my-account/mfa-verifications` endpoint to get current passkeys and other MFA verification factors.
438+
To manage existing WebAuthn passkeys, you can use the [`GET /api/my-account/mfa-verifications`](https://openapi.logto.io/operation/operation-getmfaverifications) endpoint to get current passkeys and other MFA verification factors.
422439

423440
```bash
424441
curl https://[tenant-id].logto.app/api/my-account/mfa-verifications \
@@ -445,7 +462,7 @@ The response body would be like:
445462
- `name`: the name of the passkey, optional field.
446463
- `agent`: the user agent of the passkey.
447464

448-
Update the passkey name:
465+
Update the passkey name using [`PATCH /api/my-account/mfa-verifications/{verificationId}/name`](https://openapi.logto.io/operation/operation-updatemfaverificationname) endpoint:
449466

450467
```bash
451468
curl -X PATCH https://[tenant-id].logto.app/api/my-account/mfa-verifications/{verificationId}/name \
@@ -455,7 +472,7 @@ curl -X PATCH https://[tenant-id].logto.app/api/my-account/mfa-verifications/{ve
455472
--data-raw '{"name":"..."}'
456473
```
457474

458-
Delete the passkey:
475+
Delete the passkey using [`DELETE /api/my-account/mfa-verifications/{verificationId}`](https://openapi.logto.io/operation/operation-deletemfaverification) endpoint:
459476

460477
```bash
461478
curl -X DELETE https://[tenant-id].logto.app/api/my-account/mfa-verifications/{verificationId} \
@@ -470,10 +487,12 @@ Remember to [enable MFA and TOTP](/end-user-flows/mfa) first.
470487
:::
471488

472489
:::note
473-
To use this method, you need to enable the `mfa` field in the account center settings.
490+
To use this method, you need to enable the `mfa` field in the [account center settings](#how-to-enable-account-api).
474491
:::
475492

476-
**Step 1: Generate a TOTP secret.**
493+
**Step 1: Generate a TOTP secret**
494+
495+
Use the [`POST /api/my-account/mfa-verifications/totp-secret/generate`](https://openapi.logto.io/operation/operation-generatetotpsecret) endpoint to generate a TOTP secret.
477496

478497
```bash
479498
curl -X POST https://[tenant-id].logto.app/api/my-account/mfa-verifications/totp-secret/generate \
@@ -489,7 +508,7 @@ The response body would be like:
489508
}
490509
```
491510

492-
**Step 2: Display the TOTP secret to the user.**
511+
**Step 2: Display the TOTP secret to the user**
493512

494513
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).
495514

@@ -505,9 +524,9 @@ Example:
505524
otpauth://totp/YourApp:user@example.com?secret=JBSWY3DPEHPK3PXP&issuer=YourApp
506525
```
507526

508-
**Step 3: Bind the TOTP factor.**
527+
**Step 3: Bind the TOTP factor**
509528

510-
After the user has added the secret to their authenticator app, they need to verify it and bind it to their account:
529+
After the user has added the secret to their authenticator app, they need to verify it and bind it to their account. Use the [`POST /api/my-account/mfa-verifications`](https://openapi.logto.io/operation/operation-addmfaverification) endpoint to bind the TOTP factor.
511530

512531
```bash
513532
curl -X POST https://[tenant-id].logto.app/api/my-account/mfa-verifications \
@@ -532,10 +551,12 @@ Remember to [enable MFA and backup codes](/end-user-flows/mfa) first.
532551
:::
533552

534553
:::note
535-
To use this method, you need to enable the `mfa` field in the account center settings.
554+
To use this method, you need to enable the `mfa` field in the [account center settings](#how-to-enable-account-api).
536555
:::
537556

538-
**Step 1: Generate new backup codes:**
557+
**Step 1: Generate new backup codes**
558+
559+
Use the [`POST /api/my-account/mfa-verifications/backup-codes/generate`](https://openapi.logto.io/operation/operation-generatemyaccountbackupcodes) endpoint to generate a new set of 10 backup codes.
539560

540561
```bash
541562
curl -X POST https://[tenant-id].logto.app/api/my-account/mfa-verifications/backup-codes/generate \
@@ -551,9 +572,8 @@ The response body would be like:
551572
}
552573
```
553574

554-
**Step 2: Display backup codes to the user:**
575+
**Step 2: Display backup codes to the user**
555576

556-
:::important
557577
Before binding the backup codes to the user's account, you must display them to the user and instruct them to:
558578

559579
- Download or write down these codes immediately
@@ -562,9 +582,10 @@ Before binding the backup codes to the user's account, you must display them to
562582
- Know that these codes are their last resort if they lose access to their primary MFA methods
563583

564584
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-
:::
566585

567-
**Step 3: Bind backup codes to the user account:**
586+
**Step 3: Bind backup codes to the user account**
587+
588+
Use the [`POST /api/my-account/mfa-verifications`](https://openapi.logto.io/operation/operation-addmfaverification) endpoint to bind the backup codes to the user's account.
568589

569590
```bash
570591
curl -X POST https://[tenant-id].logto.app/api/my-account/mfa-verifications \
@@ -586,7 +607,9 @@ curl -X POST https://[tenant-id].logto.app/api/my-account/mfa-verifications \
586607

587608
:::
588609

589-
**View existing backup codes:**
610+
**View existing backup codes**
611+
612+
To view existing backup codes and their usage status, use the [`GET /api/my-account/mfa-verifications/backup-codes`](https://openapi.logto.io/operation/operation-getbackupcodes) endpoint:
590613

591614
```bash
592615
curl https://[tenant-id].logto.app/api/my-account/mfa-verifications/backup-codes \

docs/logto-cloud/custom-domain.mdx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@ Once you've configured your settings, both your custom domain name and the defau
7272

7373
In this article, we assume that your custom domain is `auth.example.com`.
7474

75-
<img src="/img/assets/custom-domain-added.jpeg" alt="Custom domain added" />
76-
7775
:::
7876

7977
### Updating the SDK endpoint for applications \{#updating-the-sdk-endpoint-for-applications}

0 commit comments

Comments
 (0)