Skip to content

Commit 39f48b3

Browse files
committed
update page
1 parent 0c1307f commit 39f48b3

File tree

3 files changed

+93
-58
lines changed

3 files changed

+93
-58
lines changed

fern/products/docs/docs.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,8 @@ navigation:
152152
contents:
153153
- page: SSO
154154
path: ./pages/authentication/sso.mdx
155-
- section: Role based access control (RBAC)
155+
- page: Role based access control (RBAC)
156156
path: ./pages/authentication/rbac.mdx
157-
contents:
158-
- page: RBAC in MDX pages
159-
path: ./pages/authentication/rbac-in-pages.mdx
160157
- page: API Key Injection
161158
path: ./pages/api-references/autopopulate-api-key.mdx
162159
- section: Enterprise

fern/products/docs/pages/authentication/rbac-in-pages.mdx

Lines changed: 0 additions & 34 deletions
This file was deleted.

fern/products/docs/pages/authentication/rbac.mdx

Lines changed: 92 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ description: Learn how to restrict access to your documentation using role-based
66

77
<Note>RBAC is part of the pro plan.</Note>
88

9+
## Introduction
10+
911
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.
1012

11-
## Use cases
13+
### Use cases
1214

1315
Role-based access control is helpful for scenarios such as:
1416

@@ -18,12 +20,50 @@ Role-based access control is helpful for scenarios such as:
1820
- **Tiered access**: Offer different documentation levels based on subscription tiers
1921
- **Customer-specific content**: Show different documentation based on customer type or plan
2022

21-
## How it works
23+
### How it works
2224

2325
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.
2426

2527
Below, we walk through each of the steps required to configure RBAC.
2628

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+
2767
<Steps>
2868
### Define all the `roles` in your docs.yml
2969

@@ -41,7 +81,33 @@ roles:
4181
The `everyone` role is special. Every user has this role (including unauthenticated users).
4282
</Info>
4383

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
45111

46112
You can designate viewers on the following navigation items:
47113
- `products`
@@ -76,28 +142,34 @@ navigation:
76142

77143
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.
78144

79-
### Configure authentication via a `fern_token`
145+
### Access control within MDX pages
80146

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.
84148

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
86150

87-
```json
88-
{
89-
"fern": {
90-
"roles": ["partners"]
91-
}
92-
}
93-
```
151+
Use the `<If />` component to conditionally render content based on user roles:
94152

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+
```
96160

97-
When you're ready to implement RBAC, **contact [email protected]** to receive your secret key for JWT signing.
161+
#### Multiple roles
98162

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:
100164

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+
```
102172

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.
175+
</Note>

0 commit comments

Comments
 (0)