Skip to content

Commit 223d3bc

Browse files
authored
Update nav structure for Docs Authentication section, add info on OAuth key injection flow (#282)
1 parent a648993 commit 223d3bc

File tree

7 files changed

+198
-58
lines changed

7 files changed

+198
-58
lines changed

fern/products/docs/docs.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,15 @@ navigation:
171171
- section: Authentication
172172
collapsed: true
173173
contents:
174-
- page: SSO
175-
path: ./pages/authentication/sso.mdx
174+
- page: Overview
175+
path: ./pages/authentication/overview.mdx
176176
- page: Role based access control (RBAC)
177177
path: ./pages/authentication/rbac.mdx
178178
slug: rbac
179179
- page: API Key Injection
180180
path: ./pages/api-references/autopopulate-api-key.mdx
181+
- page: SSO
182+
path: ./pages/authentication/sso.mdx
181183
- section: Enterprise
182184
collapsed: true
183185
contents:

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

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,17 @@ Fern can integrate with your authentication flow, allowing users to login and ha
1313

1414
With this feature, you can **create new users of your API** directly from within your documentation.
1515

16-
## How it works
16+
## Integrating with your auth flow
17+
18+
API key injection can work in two different ways depending on your company's authentication setup: **JWT or OAuth**.
19+
20+
* **JWT Flow:** You handle the entire auth flow and just give Fern a JWT cookie
21+
* **OAuth Flow:** You give Fern access, and Fern directly initiates the OAuth handshake process
22+
23+
<AccordionGroup toc={true}>
24+
<Accordion title="JWT" toc={true}>
25+
26+
### How the JWT flow works
1727

1828
To enable this feature, you need to configure authentication so that Fern can securely retrieve API keys for your users. The process works as follows:
1929

@@ -77,11 +87,49 @@ The JWT should have a structure similar to:
7787

7888
</CodeBlocks>
7989

80-
## Setting up auto-populated API keys
90+
#### Architecture diagram
91+
92+
<Markdown src="/snippets/jwt-auth-diagram.mdx"/>
93+
94+
#### Setting up auto-populated API keys
8195

8296
- [ ] Reach out to Fern to get your secret key
83-
- [ ] Send Fern the URL of your authentication page (this is where users will be redirected to after clicking the "Login" button in the API Explorer)
97+
- [ ] Send Fern the URL of your authentication page. This is where users will be redirected to after clicking the "Login" button in the API Explorer.
8498
- [ ] Add logic to your service to set the `fern_token` cookie when a user logs in
8599

86100
<Tip>For an example of how to set up the `fern_token` cookie, see our demo implementation [here](https://github.com/fern-api/fern-platform/blob/app/packages/fern-docs/bundle/src/app/%5Bhost%5D/%5Bdomain%5D/api/fern-docs/auth/fern-token-demo/route.ts).</Tip>
87101

102+
</Accordion>
103+
<Accordion title="OAuth" toc={true}>
104+
105+
### How the OAuth flow works
106+
107+
To enable this feature, you need to configure OAuth authentication so that Fern can securely retrieve API keys for your users through your OAuth provider. Here's how the process works:
108+
109+
1. When a user clicks the "Login" button in the API Explorer, Fern initiates an OAuth flow by making a request to your authorization endpoint.
110+
1. The user is redirected to your OAuth provider's login page where they authenticate using your existing auth system.
111+
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.
112+
1. Fern sets a `fern_token` cookie containing the user's authentication credentials and automatically populates their API key in the API Explorer.
113+
114+
#### Architecture diagram
115+
116+
<Markdown src="/snippets/oauth-diagram.mdx"/>
117+
118+
#### Setting up auto-populated API keys
119+
120+
To enable API key injection, you'll need to:
121+
- [ ] Set up an authenticated account for Fern so Fern can authorize users on your behalf.
122+
- [ ] Configure your OAuth application to return user API keys when Fern requests them
123+
124+
Then, you'll need to send Fern the following items:
125+
- The client ID and client secret for Fern's authenticated account
126+
- The URL of your authentication endpoint. This is where users will be redirected to after clicking the "Login" button in the API Explorer.
127+
- The URL of your token endpoint. This is where Fern exchanges codes for tokens.
128+
129+
</Accordion>
130+
</AccordionGroup>
131+
132+
133+
134+
135+
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
title: Overview of authentication options
3+
description: Understand the different authentication options Fern offers
4+
---
5+
6+
Fern offers two methods of authentication, Single Sign-On (SSO) and Role-Based Access Control (RBAC).
7+
8+
**For most situations, we recommend using RBAC** for granular access control over your documentation. RBAC works well for sites with multiple audiences (internal teams, partners, customers) and supports API key injection to auto-populate code examples.
9+
10+
API key injection can be set up using either JWT or OAuth, depending on your existing authentication system.
11+
12+
**SSO is simpler** but only provides basic login functionality - it doesn't support RBAC or API key injection. SSO works well for internal-only documentation where everyone should see the same content.
13+
14+
15+
16+
Learn more about Fern's authentication options:
17+
18+
<CardGroup cols={3}>
19+
<Card title="Role-based access control" icon="fa-duotone fa-people-group" href="/docs/authentication/rbac">
20+
Granular access for different audiences
21+
</Card>
22+
<Card title="API Key Injection" icon="fa-duotone fa-key" href="/docs/authentication/api-key-injection">
23+
JWT or OAuth flows available
24+
</Card>
25+
<Card title="SSO" icon="fa-duotone fa-user-check" href="/docs/authentication/sso">
26+
Basic functionality and simple setup
27+
</Card>
28+
</CardGroup>

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

Lines changed: 23 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -24,43 +24,6 @@ Role-based access control is helpful for scenarios such as:
2424

2525
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.
2626

27-
Below, we walk through each of the steps required to configure RBAC.
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->>U: User is shown a 404 page
50-
end
51-
else No cookie
52-
F->>R: Redirect to login page
53-
R->>A: Authenticate user
54-
end
55-
56-
Note over A: User logs in
57-
58-
A->>A: Generate JWT with roles
59-
A->>F: Set fern_token cookie
60-
F->>F: Validate JWT and roles
61-
F->>U: Show restricted content
62-
```
63-
6427
## Set up RBAC
6528

6629
<Steps>
@@ -82,10 +45,16 @@ The `everyone` role is special. Every user has this role (including unauthentica
8245

8346
### Configure authentication via a `fern_token`
8447

85-
In this step, we will configure authentication so that Fern can understand what roles a particular user has. Fern expects the user's
86-
browser session to have a cookie called `fern_token`. If the cookie is not present, the user will be redirected to your company's
87-
login page.
48+
In this step, we will configure authentication so that Fern can understand what roles a particular user has.
49+
50+
Fern expects the user's browser session to have a cookie called `fern_token`. If
51+
the cookie is not present, the user will be redirected to your company's login
52+
page.
8853

54+
Below, we walk through each of the steps required to configure RBAC with either JWT or OAuth.
55+
56+
<AccordionGroup>
57+
<Accordion title="JWT">
8958
**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`.
9059

9160
```json
@@ -96,11 +65,22 @@ login page.
9665
}
9766
```
9867

99-
### Contact Fern for setup
68+
<Markdown src="/snippets/jwt-auth-diagram.mdx"/>
10069

101-
When you're ready to implement RBAC, **contact [email protected]** to receive your secret key for JWT signing.
70+
</Accordion>
71+
<Accordion title="OAuth">
72+
73+
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.
74+
You are responsible for configuring your OAuth endpoints to return user role information.
75+
76+
<Markdown src="/snippets/oauth-diagram.mdx"/>
77+
78+
</Accordion>
79+
</AccordionGroup>
80+
81+
### Contact Fern for setup
10282

103-
You'll also need to provide the URL where Fern should send unauthenticated users to log in.
83+
When you're ready to implement RBAC, **contact [email protected]**.
10484

10585
<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>
10686

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,41 @@
11
---
22
title: Single Sign-On
3-
subtitle: Enterprise authentication for secure access to your Fern dashboard
3+
subtitle: Enterprise authentication for secure access to your docs
44
---
55

6-
Fern’s Single Sign-On (SSO) is an enterprise feature that lets your team securely access the Fern dashboard at `dashboard.buildwithfern.com` using your organization’s identity provider. This is designed for internal contributors, such as technical writers, product managers, or engineers, who need access to want to contribute to your documentation, view web analytics, or manage organizational settings.
6+
Fern’s Single Sign-On (SSO) is an enterprise feature that lets your team securely access your docs through your organization’s identity provider.
7+
8+
<Note>SSO does not support Role-Based Access Control or API Key Injection.</Note>
79

810
## What SSO unlocks
911

10-
When SSO is enabled for your organization, authenticated users of Fern gain access to:
12+
When SSO is enabled for your organization, authenticated users of Fern can:
1113

12-
- **Manage Users of your Organization**: Add teammates and configure settings for your organization
13-
- **Access Ask Fern Analytics**: See AI-assisted search usage and browse verbatim user questions
14-
- **View Web Analytics**: Track key site metrics, like page views and unique visitors **(coming soon)**
1514
- **Use the Visual Editor**: Make edits to your docs from the browser
15+
- **Send Authenticated Preview Links** Only authenticated users can view [preview links](docs/preview-publish/previewing-changes-locally)
1616

1717
## How it works
1818

19-
Fern's SSO integration allows your team to use their existing corporate credentials to access the Fern dashboard. Instead of managing separate Fern accounts, users authenticate through your organization's identity provider and are automatically granted appropriate access to your Fern resources.
19+
Fern's SSO integration allows your team to use their existing corporate credentials to access your Fern Docs site.
20+
21+
### Architecture diagram
22+
23+
```mermaid
24+
sequenceDiagram
25+
participant U as User
26+
participant F as Fern Docs
27+
participant I as Identity Provider
28+
29+
U->>F: Click "Login"
30+
F->>I: Redirect to SSO login
31+
32+
Note over I: User authenticates with corporate credentials
33+
34+
I->>I: Validate user credentials
35+
I->>F: Redirect back with fern_token
36+
F->>F: Grant access to organizational features
37+
F->>U: Show docs site
38+
```
2039

2140
## Supported identity providers
2241

@@ -25,6 +44,7 @@ Fern supports SSO integration with any identity provider that implements industr
2544
- **SAML 2.0**: Compatible with providers like Okta, OneLogin, Azure AD, and others
2645
- **OIDC (OpenID Connect)**: Works with Google Workspace, Auth0, and other OIDC-compliant providers
2746

28-
<Note>
29-
SSO is available as part of the Enterprise plan. Reach out via Slack or [contact our team](https://buildwithfern.com/contact) to begin the SSO setup process.
30-
</Note>
47+
## Setting up SSO
48+
49+
SSO is available as part of the Enterprise plan. Reach out via Slack or [contact our team](https://buildwithfern.com/contact) to begin the SSO setup process. Fern will work with one of your security administrators to connect to your identity provider.
50+

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)