Set up OAuth
Fern-managed authentication integrated with your login system
With OAuth, Fern manages the auth flow for you. You give Fern access to your OAuth provider, and Fern handles the fern_token cookie that integrates your docs with your existing login system. Like JWT, OAuth enables:
- RBAC — restrict content by user role
- API key injection — pre-fill API keys in the API Explorer
How it works
- A user clicks Login on your docs site and Fern initiates an OAuth flow with your provider.
- The user authenticates on your OAuth provider’s login page.
- Your provider redirects back to Fern with an authorization code, which Fern exchanges for an access token.
- Fern sets a
fern_tokencookie containing the user’s access and credentials.
Architecture diagram
Configuration
Create an OAuth client
Go to your OAuth provider’s dashboard and create a new web application client.
Allowlist Fern callbacks
Allowlist the following callback in your OAuth provider:
https://<your-domain>/api/fern-docs/oauth2/callback.
Replace <your-domain> with your Fern Docs domain. If you use both a .docs.buildwithfern.com and a custom domain, allowlist both.
Send OAuth client details to Fern
Send the following to support@buildwithfern.com or your dedicated Slack channel:
- Docs domain
- Client ID
- Client secret
- Authorization URL (e.g.
https://<your-oauth-tenant>/oauth2/authorize) - Token URL (e.g.
https://<your-oauth-tenant>/oauth2/token) - Scopes (e.g.
openid,profile,email) - Issuer URL (e.g.
https://<your-domain>)
Specifying an audience
If your client is connected to an API, you may need to specify an audience in the authentication request.
The updated authorization URL may look like this: https://<your-oauth-tenant>/oauth2/authorize?audience=<your-api-identifier>
Wait for Fern to configure OAuth
Fern will configure OAuth on your site. You’ll receive a notification when authentication is ready.
Enable RBAC or API key injection (optional)
Once OAuth is working, configure the features you need:
RBAC
Add a custom claim
Add a custom claim to your OAuth provider’s token response so that Fern can determine each user’s roles. The resulting token response should look something like this:
Using a claim other than roles
Some OAuth providers have strict requirements for custom claims. If you need to use a claim other than roles, reach out to Fern and specify which claim should be parsed for the user’s roles.
Using Auth0
To add a custom claim to Auth0, you need to create a custom action. This action will be used to add the custom claim to the token response.
- Go to the Actions tab in the Auth0 dashboard.
- Create a Custom Action.
- Select Login/Post Login.
- Add logic to set a roles.
Example Action
- Click Create.
- Add the action to your Post Login Flow.
Configure RBAC
Once your token response includes roles, define those roles in docs.yml and assign them to navigation items and page content. See Role-based access control for the full setup.
API key injection
Set up an authenticated account for Fern so Fern can authorize users on your behalf, and configure your OAuth application to return user API keys when Fern requests tokens. Contact support@buildwithfern.com to coordinate this setup.