|
| 1 | +--- |
| 2 | +sidebar_position: 3 |
| 3 | +--- |
| 4 | + |
| 5 | +# Custom ID token |
| 6 | + |
| 7 | +## Introduction \{#introduction} |
| 8 | + |
| 9 | +[ID token](https://auth.wiki/id-token) is a special type of token defined by the [OpenID Connect (OIDC)](https://auth.wiki/openid-connect) protocol. It serves as an identity assertion issued by the authorization server (Logto) after a user successfully authenticates, carrying claims about the authenticated user's identity. |
| 10 | + |
| 11 | +Unlike [access tokens](/developers/custom-token-claims) which are used to access protected resources, ID tokens are specifically designed to convey authenticated user identity to client applications. They are [JSON Web Tokens (JWTs)](https://auth.wiki/jwt) that contain claims about the authentication event and the authenticated user. |
| 12 | + |
| 13 | +## How ID token claims work \{#how-id-token-claims-work} |
| 14 | + |
| 15 | +In Logto, ID token claims are divided into two categories: |
| 16 | + |
| 17 | +1. **Standard OIDC claims**: Defined by the OIDC specification, these claims are entirely determined by the scopes requested during authentication. |
| 18 | +2. **Extended claims**: Claims extended by Logto to carry additional identity information, controlled by a **dual-condition model** (Scope + Toggle). |
| 19 | + |
| 20 | +```mermaid |
| 21 | +flowchart TD |
| 22 | + A[User authentication request] --> B{Requested scopes} |
| 23 | + B --> C[Standard OIDC scopes] |
| 24 | + B --> D[Extended scopes] |
| 25 | + C --> E[Standard claims included in ID token] |
| 26 | + D --> F{Console toggle enabled?} |
| 27 | + F -->|Yes| G[Extended claims included in ID token] |
| 28 | + F -->|No| H[Claims not included] |
| 29 | +``` |
| 30 | + |
| 31 | +## Standard OIDC claims \{#standard-oidc-claims} |
| 32 | + |
| 33 | +Standard claims are completely governed by the OIDC specification. Their inclusion in the ID token depends solely on the scopes your application requests during authentication. Logto does not provide any option to disable or selectively exclude individual standard claims. |
| 34 | + |
| 35 | +The following table shows the mapping between standard scopes and their corresponding claims: |
| 36 | + |
| 37 | +| Scope | Claims | |
| 38 | +| --------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
| 39 | +| `openid` | `sub` | |
| 40 | +| `profile` | `name`, `family_name`, `given_name`, `middle_name`, `nickname`, `preferred_username`, `profile`, `picture`, `website`, `gender`, `birthdate`, `zoneinfo`, `locale`, `updated_at` | |
| 41 | +| `email` | `email`, `email_verified` | |
| 42 | +| `phone` | `phone_number`, `phone_number_verified` | |
| 43 | +| `address` | `address` | |
| 44 | + |
| 45 | +For example, if your application requests the `openid profile email` scopes, the ID token will include all claims from the `openid`, `profile`, and `email` scopes. |
| 46 | + |
| 47 | +## Extended claims \{#extended-claims} |
| 48 | + |
| 49 | +Beyond the standard OIDC claims, Logto extends additional claims that carry identity information specific to the Logto ecosystem. These extended claims follow a **dual-condition model** to be included in the ID token: |
| 50 | + |
| 51 | +1. **Scope condition**: The application must request the corresponding scope during authentication. |
| 52 | +2. **Console toggle**: The administrator must enable the claim's inclusion in the ID token through Logto Console. |
| 53 | + |
| 54 | +Both conditions must be satisfied simultaneously. The scope serves as the protocol-layer access declaration, while the toggle serves as the product-layer exposure control — their responsibilities are clear and non-substitutable. |
| 55 | + |
| 56 | +### Available extended scopes and claims \{#available-extended-scopes-and-claims} |
| 57 | + |
| 58 | +| Scope | Claims | Description | Included by default | |
| 59 | +| ------------------------------------ | ------------------------------ | --------------------------------------- | ------------------- | |
| 60 | +| `custom_data` | `custom_data` | Custom data stored on the user object | | |
| 61 | +| `identities` | `identities`, `sso_identities` | User's linked social and SSO identities | | |
| 62 | +| `roles` | `roles` | User's assigned roles | ✅ | |
| 63 | +| `urn:logto:scope:organizations` | `organizations` | User's organization IDs | ✅ | |
| 64 | +| `urn:logto:scope:organizations` | `organization_data` | User's organization data | | |
| 65 | +| `urn:logto:scope:organization_roles` | `organization_roles` | User's organization role assignments | ✅ | |
| 66 | + |
| 67 | +### Configure in Logto Console \{#configure-in-logto-console} |
| 68 | + |
| 69 | +To enable extended claims in the ID token: |
| 70 | + |
| 71 | +1. Navigate to <CloudLink to="/customize-jwt">Console > Custom JWT</CloudLink>. |
| 72 | +2. Toggle on the claims you want to include in the ID token. |
| 73 | +3. Ensure your application requests the corresponding scopes during authentication. |
| 74 | + |
| 75 | +## Related resources \{#related-resources} |
| 76 | + |
| 77 | +<Url href="/developers/custom-token-claims">Custom access token</Url> |
| 78 | + |
| 79 | +<Url href="https://openid.net/specs/openid-connect-core-1_0.html#IDToken"> |
| 80 | + OpenID Connect Core - ID Token |
| 81 | +</Url> |
0 commit comments