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: authentication-personalization/personalization-setup.mdx
+98-5Lines changed: 98 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,9 +4,102 @@ description: "Let users log in for customized documentation experiences"
4
4
icon: "user-cog"
5
5
---
6
6
7
-
Personalization lets you customize your documentation based on user information. This guide covers setup for each available handshake method.
7
+
Customize your documentation based on user information, including prefilling API playground inputs and adding dynamic content.
8
+
9
+
## User data format
10
+
11
+
When implementing personalization, your system returns user data in a specific format that enables content customization. This data can be sent as either a raw JSON object or within a signed JWT, depending on your handshake method. The shape of the data is the same for both.
12
+
13
+
```tsx
14
+
typeUser= {
15
+
expiresAt?:number;
16
+
groups?:string[];
17
+
content?:Record<string, any>;
18
+
apiPlaygroundInputs?: {
19
+
header?:Record<string, any>;
20
+
query?:Record<string, any>;
21
+
cookie?:Record<string, any>;
22
+
server?:Record<string, string>;
23
+
};
24
+
};
25
+
```
26
+
27
+
<ParamField
28
+
path="expiresAt"
29
+
type="number"
30
+
>
31
+
Session expiration time in **seconds since epoch**. If the user loads a page after this time, their stored data is automatically deleted and they must reauthenticate.
32
+
<Warning><b>For JWT handshakes:</b> This differs from the JWT's `exp` claim, which determines when a JWT is considered invalid. Set the JWT `exp` claim to a short duration (10 seconds or less) for security. Use `expiresAt` for the actual session length (hours to weeks).</Warning>
33
+
</ParamField>
34
+
<ParamField
35
+
path="groups"
36
+
type="string[]"
37
+
>
38
+
A list of groups that the user belongs to. Pages with a matching `groups` field in their metadata will be visible to this user.
39
+
40
+
**Example**: User with `groups: ["admin", "engineering"]` can access pages tagged with either the `admin` or `engineering` groups.
41
+
</ParamField>
42
+
<ParamField
43
+
path="content"
44
+
type="object"
45
+
>
46
+
Custom data accessible in your `MDX` content via the `user` variable. Use this for dynamic personalization throughout your documentation.
Welcome back, {user.firstName}! Your {user.plan} plan includes...
56
+
```
57
+
With the example `user` data, this would render as: Welcome back, Ronan! Your Enterprise plan includes...
58
+
</ParamField>
59
+
<ParamField
60
+
path="apiPlaygroundInputs"
61
+
type="object"
62
+
>
63
+
User-specific values that will be prefilled in the API playground if supplied. Save users time when testing your APIs with their own data.
64
+
65
+
**Example**:
66
+
```json
67
+
{
68
+
"header": { "X-API-Key": "user_api_key_123" },
69
+
"server": { "subdomain": "foo" },
70
+
"query": { "org_id": "12345" }
71
+
}
72
+
```
73
+
If a user makes requests at a specific subdomain, you can send `{ server: { subdomain: 'foo' } }` as an `apiPlaygroundInputs` field. This value will be prefilled on any API page with the `subdomain` value.
74
+
75
+
<Note>The `header`, `query`, and `cookie` fields will only prefill if they are part of your [OpenAPI security scheme](https://swagger.io/docs/specification/authentication/). If a field is in either the `Authorization` or `Server` sections, it will prefill. Creating a standard header parameter named `Authorization` will not enable this feature.</Note>
76
+
</ParamField>
77
+
78
+
### Example user data
8
79
9
-
**Need help choosing?** See the [overview](/authentication-personalization/overview) to compare options.
80
+
```json
81
+
{
82
+
"expiresAt": 1735689600,
83
+
"groups": ["admin", "beta-users"],
84
+
"content": {
85
+
"firstName": "Jane",
86
+
"lastName": "Smith",
87
+
"company": "TechCorp",
88
+
"plan": "Enterprise",
89
+
"region": "us-west"
90
+
},
91
+
"apiPlaygroundInputs": {
92
+
"header": {
93
+
"Authorization": "Bearer abc123",
94
+
"X-Org-ID": "techcorp"
95
+
},
96
+
"server": {
97
+
"environment": "production",
98
+
"region": "us-west"
99
+
}
100
+
}
101
+
}
102
+
```
10
103
11
104
## Configuring personalization
12
105
@@ -33,7 +126,7 @@ Select the handshake method that you want to configure.
33
126
<Steptitle="Integrate Mintlify personalization into your login flow.">
34
127
Modify your existing login flow to include these steps after user login:
35
128
36
-
* Create a JWT containing the logged in user's info in the `User` format. See [Sending Data](/authentication-personalization/sending-data) for more information.
129
+
* Create a JWT containing the logged in user's info in the `User` format. See the [User data format](#user-data-format) section above for more information.
37
130
* Sign the JWT with the secret key, using the ES256 algorithm.
38
131
* Create a redirect URL back to your docs, including the JWT as the hash.
39
132
</Step>
@@ -95,7 +188,7 @@ To redirect users to specific sections after login, use this URL format: `https:
95
188
<Steptitle="Create user info API endpoint.">
96
189
Create an API endpoint that:
97
190
* Accepts OAuth access tokens for authentication.
98
-
* Returns user data in the `User` format. See [Sending Data](/authentication-personalization/sending-data) for more information.
191
+
* Returns user data in the `User` format. See the [User data format](#user-data-format) section above for more information.
99
192
* Defines the scopes for access.
100
193
</Step>
101
194
<Steptitle="Configure your OAuth personalization settings.">
@@ -157,7 +250,7 @@ Your documentation is hosted at `foo.com/docs` and you have an existing OAuth se
157
250
<Steptitle="Create user info API endpoint.">
158
251
Create an API endpoint that:
159
252
* Uses your existing session authentication to identify users
160
-
* Returns user data in the `User` format (see [Sending Data](/authentication-personalization/sending-data))
253
+
* Returns user data in the `User` format (see the [User data format](#user-data-format) section above)
161
254
* If the API domain and the docs domain **do not exactly match**:
162
255
* Add the docs domain to your API's `Access-Control-Allow-Origin` header (must not be `*`).
163
256
* Set your API's `Access-Control-Allow-Credentials` header to `true`.
0 commit comments