Skip to content

Commit e202a23

Browse files
committed
put diagrams in snippets
1 parent bcc2b90 commit e202a23

File tree

4 files changed

+71
-68
lines changed

4 files changed

+71
-68
lines changed

fern/products/docs/pages/api-references/autopopulate-api-key.mdx

Lines changed: 4 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -89,38 +89,7 @@ The JWT should have a structure similar to:
8989

9090
#### Architecture diagram
9191

92-
```mermaid
93-
sequenceDiagram
94-
participant U as User
95-
participant F as Fern Docs
96-
participant R as Redirect URL
97-
participant A as Auth System
98-
99-
U->>F: Visit restricted page
100-
F->>F: Check fern_token cookie
101-
102-
alt Cookie exists
103-
F->>F: Decode JWT with secret key
104-
F->>F: Extract roles from JWT
105-
F->>F: Check if user has required role
106-
107-
alt User has required role
108-
F->>U: Show restricted content
109-
else User lacks required role
110-
F->>U: User is shown a 404 page
111-
end
112-
else No cookie
113-
F->>R: Redirect to login page
114-
R->>A: Authenticate user
115-
end
116-
117-
Note over A: User logs in
118-
119-
A->>A: Generate JWT with roles
120-
A->>F: Set fern_token cookie
121-
F->>F: Validate JWT and roles
122-
F->>U: Show restricted content
123-
```
92+
<Markdown src="/snippets/jwt-auth-diagram.mdx"/>
12493

12594
#### Setting up auto-populated API keys
12695

@@ -142,38 +111,9 @@ To enable this feature, you need to configure OAuth authentication so that Fern
142111
1. After successful authentication, your OAuth provider redirects back to Fern with an authorization code, which Fern exchanges for an access token at your token endpoint.
143112
1. Fern sets a `fern_token` cookie containing the user's authentication credentials and automatically populates their API key in the API Explorer.
144113

145-
### Architecture diagram
146-
147-
```mermaid
148-
sequenceDiagram
149-
participant U as User
150-
participant F as Fern Docs
151-
participant A as OAuth2 Provider
152-
U->>F: Visit restricted page
153-
F->>F: Check fern_token cookie
154-
155-
alt Cookie exists
156-
F->>F: Decode cookie
157-
F->>F: Verify authentication credentials
158-
Note over F: Attempt to refresh the token, if expired
159-
160-
alt User is properly authenticated
161-
F->>U: Show restricted content
162-
else User is not properly authenticated
163-
F->>U: User is shown a 404 page
164-
end
165-
else No cookie
166-
F->>A: Redirect to `/authenticate` endpoint
167-
A->>U: User authenticates
168-
U->>F: Authorization code is returned
169-
F->>A: Redirect to `/token` endpoint
170-
A->>A: Validate token request
171-
A->>F: Send authenticated access token
172-
F->>F: Set fern_token cookie
173-
F->>F: Verify authentication credentials
174-
F->>U: Show restricted content
175-
end
176-
```
114+
#### Architecture diagram
115+
116+
<Markdown src="/snippets/oauth-diagram.mdx"/>
177117

178118
#### Setting up auto-populated API keys
179119

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ Fern expects the user's browser session to have a cookie called `fern_token`. If
5151
the cookie is not present, the user will be redirected to your company's login
5252
page.
5353

54+
Below, we walk through each of the steps required to configure RBAC with either JWT or OAuth.
5455

5556
<AccordionGroup>
5657
<Accordion title="JWT">
@@ -64,19 +65,19 @@ page.
6465
}
6566
```
6667

67-
For more information on this flow, see [Auto-populate API keys](/docs/api-references/autopopulate-api-key#jwt)
68+
<Markdown src="/snippets/jwt-auth-diagram.mdx"/>
69+
6870
</Accordion>
6971
<Accordion title="OAuth">
7072

7173
Fern initiates an OAuth flow when the user needs authentication, redirecting them to your authentication endpoint. Fern creates and sets the `fern-token` cookie after completing this flow.
7274
You are responsible for configuring your OAuth endpoints to return user role information.
7375

74-
For more information on this flow, see [Auto-populate API keys](/docs/api-references/autopopulate-api-key#oauth)
76+
<Markdown src="/snippets/oauth-diagram.mdx"/>
77+
7578
</Accordion>
7679
</AccordionGroup>
7780

78-
79-
8081
### Contact Fern for setup
8182

8283
When you're ready to implement RBAC, **contact [email protected]**.

fern/snippets/jwt-auth-diagram.mdx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
```mermaid
2+
sequenceDiagram
3+
participant U as User
4+
participant F as Fern Docs
5+
participant R as Redirect URL
6+
participant A as Auth System
7+
8+
U->>F: Visit restricted page
9+
F->>F: Check fern_token cookie
10+
11+
alt Cookie exists
12+
F->>F: Decode JWT with secret key
13+
F->>F: Extract roles from JWT
14+
F->>F: Check if user has required role
15+
16+
alt User has required role
17+
F->>U: Show restricted content
18+
else User lacks required role
19+
F->>U: User is shown a 404 page
20+
end
21+
else No cookie
22+
F->>R: Redirect to login page
23+
R->>A: Authenticate user
24+
end
25+
26+
Note over A: User logs in
27+
28+
A->>A: Generate JWT with roles
29+
A->>F: Set fern_token cookie
30+
F->>F: Validate JWT and roles
31+
F->>U: Show restricted content
32+
```

fern/snippets/oauth-diagram.mdx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
```mermaid
2+
sequenceDiagram
3+
participant U as User
4+
participant F as Fern Docs
5+
participant A as OAuth2 Provider
6+
U->>F: Visit restricted page
7+
F->>F: Check fern_token cookie
8+
9+
alt Cookie exists
10+
F->>F: Decode cookie
11+
F->>F: Verify authentication credentials
12+
Note over F: Attempt to refresh the token, if expired
13+
14+
alt User is properly authenticated
15+
F->>U: Show restricted content
16+
else User is not properly authenticated
17+
F->>U: User is shown a 404 page
18+
end
19+
else No cookie
20+
F->>A: Redirect to `/authenticate` endpoint
21+
A->>U: User authenticates
22+
U->>F: Authorization code is returned
23+
F->>A: Redirect to `/token` endpoint
24+
A->>A: Validate token request
25+
A->>F: Send authenticated access token
26+
F->>F: Set fern_token cookie
27+
F->>F: Verify authentication credentials
28+
F->>U: Show restricted content
29+
end
30+
```

0 commit comments

Comments
 (0)