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: fern/products/docs/pages/authentication/rbac.mdx
+92-20Lines changed: 92 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,9 +6,11 @@ description: Learn how to restrict access to your documentation using role-based
6
6
7
7
<Note>RBAC is part of the pro plan.</Note>
8
8
9
+
## Introduction
10
+
9
11
Fern allows you to restrict parts of your navigation to individuals with specific roles. RBAC enables you to create different levels of access for different user types within your documentation.
10
12
11
-
## Use cases
13
+
###Use cases
12
14
13
15
Role-based access control is helpful for scenarios such as:
14
16
@@ -18,12 +20,50 @@ Role-based access control is helpful for scenarios such as:
18
20
-**Tiered access**: Offer different documentation levels based on subscription tiers
19
21
-**Customer-specific content**: Show different documentation based on customer type or plan
20
22
21
-
## How it works
23
+
###How it works
22
24
23
25
If a user visits content not marked as visible to the `everyone` role, Fern will check for an authentication cookie to indicate what roles that user has. If the user does not have a role matching the viewers of the page, we will redirect them to the URL you provided during setup.
24
26
25
27
Below, we walk through each of the steps required to configure RBAC.
26
28
29
+
### Architecture diagram
30
+
31
+
```mermaid
32
+
sequenceDiagram
33
+
participant U as User
34
+
participant F as Fern Docs
35
+
participant R as Redirect URL
36
+
participant A as Auth System
37
+
38
+
U->>F: Visit restricted page
39
+
F->>F: Check fern_token cookie
40
+
41
+
alt Cookie exists
42
+
F->>F: Decode JWT with secret key
43
+
F->>F: Extract roles from JWT
44
+
F->>F: Check if user has required role
45
+
46
+
alt User has required role
47
+
F->>U: Show restricted content
48
+
else User lacks required role
49
+
F->>R: Redirect to login page
50
+
R->>A: Authenticate user
51
+
end
52
+
else No cookie
53
+
F->>R: Redirect to login page
54
+
R->>A: Authenticate user
55
+
end
56
+
57
+
Note over A: User logs in
58
+
59
+
A->>A: Generate JWT with roles
60
+
A->>F: Set fern_token cookie
61
+
F->>F: Validate JWT and roles
62
+
F->>U: Show restricted content
63
+
```
64
+
65
+
## Set up RBAC
66
+
27
67
<Steps>
28
68
### Define all the `roles` in your docs.yml
29
69
@@ -41,7 +81,33 @@ roles:
41
81
The `everyone` role is special. Every user has this role (including unauthenticated users).
42
82
</Info>
43
83
44
-
### Define viewers on parts of the navigation
84
+
### Configure authentication via a `fern_token`
85
+
86
+
In this step, we will configure authentication so that Fern can understand what roles a particular user has. Fern expects the user's
87
+
browser session to have a cookie called `fern_token`. If the cookie is not present, the user will be redirected to your company's
88
+
login page.
89
+
90
+
**You are responsible for creating and setting the `fern_token` cookie in your authentication system.** Upon login, you must set a JWT for the user using a secret key that we will provide. The JWT must have a `fern` claim with a key called `roles`.
91
+
92
+
```json
93
+
{
94
+
"fern": {
95
+
"roles": ["partners"]
96
+
}
97
+
}
98
+
```
99
+
100
+
### Contact Fern for setup
101
+
102
+
When you're ready to implement RBAC, **contact [email protected]** to receive your secret key for JWT signing.
103
+
104
+
You'll also need to provide the URL where Fern should send unauthenticated users to log in.
105
+
106
+
<Note>Optional: If you'd like restricted pages to be visible but locked to unauthenticated users (rather than completely hidden), let us know during this step.</Note>
107
+
108
+
</Steps>
109
+
110
+
### Access control within navigation
45
111
46
112
You can designate viewers on the following navigation items:
47
113
- `products`
@@ -76,28 +142,34 @@ navigation:
76
142
77
143
Viewership is inherited. For example, if a section can only be viewed by `admins`, then all its pages and nested sections can also only be viewed by admins.
78
144
79
-
### Configure authentication via a `fern_token`
145
+
### Access control within MDX pages
80
146
81
-
In this step, we will configure authentication so that Fern can understand what roles a particular user has. Fern expects the user's
82
-
browser session to have a cookie called `fern_token`. If the cookie is not present, the user will be redirected to your company's
83
-
login page.
147
+
You can restrict specific content within your MDX pages to users with certain roles. This allows you to show different content to different user types on the same page.
84
148
85
-
**You are responsible for creating and setting the `fern_token` cookie in your authentication system.** Upon login, you must set a JWT for the user using a secret key that we will provide. The JWT must have a `fern` claim with a key called `roles`.
149
+
#### Basic usage
86
150
87
-
```json
88
-
{
89
-
"fern": {
90
-
"roles": ["partners"]
91
-
}
92
-
}
93
-
```
151
+
Use the `<If />` component to conditionally render content based on user roles:
94
152
95
-
### Contact Fern for setup
153
+
```mdx
154
+
<If roles={["beta-users"]}>
155
+
<Callout>
156
+
This callout is only visible to beta users.
157
+
</Callout>
158
+
</If>
159
+
```
96
160
97
-
When you're ready to implement RBAC, **contact [email protected]** to receive your secret key for JWT signing.
161
+
#### Multiple roles
98
162
99
-
You'll also need to provide the URL where Fern should send unauthenticated users to log in.
163
+
You can specify multiple roles. Content will be visible to users who have **any** of the specified roles:
100
164
101
-
<Note>Optional: If you'd like restricted pages to be visible but locked to unauthenticated users (rather than completely hidden), let us know during this step.</Note>
165
+
```mdx
166
+
<If roles={["partners", "admins"]}>
167
+
<Callout>
168
+
This content is visible to both partners and admins.
169
+
</Callout>
170
+
</If>
171
+
```
102
172
103
-
</Steps>
173
+
<Note>
174
+
The `<If>` component respects the same role inheritance rules as navigation items. If a user has access to a page, they can see all content on that page that matches their roles.
0 commit comments